help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Repeating and shifting a vector


From: michele
Subject: Re: Repeating and shifting a vector
Date: Thu, 5 Mar 2020 17:59:09 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0


On 3/5/20 5:33 PM, Henk Borsje wrote:

Is there a way to create a matrix from a vector, where each new row is either shifted or rotated one element, but if possible without a for-loop?

 

A simple example:

 

From A = [1 2 3 4 5 6 7 8 9 10]

 

Create B = [1 2 3 4 5 6 7 8 9 10 ; 0 1 2 3 4 5 6 7 8 9; 0 0 1 2 3 4 5 6 7 8]

 

This shows the last element dropping off, but a shift would be just as useful.

 

Any ideas will be welcome.

 

Henk Borsje



    
You can achieve it using the toeplitz command. Your example can be obtained by:
r = 1:10;
c = [1; 0; 0];
B = toeplitz(c, r)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]