From: Juliette Salexa on 4 Feb 2010 10:49 Hello, I was wondering if there's a neat/efficient way to generate the matrix: [1 2 3 4 5 ; 0 1 2 3 4 ; 0 0 1 2 3 ; 0 0 0 1 2 ; 0 0 0 0 1 ] using only the vector: [1 2 3 4 5] The way I'm doing it right now uses CIRCSHIFT, but it seems like there must be a much more scalable and neat way to do this, any suggestions ?? Thank you! juliette
From: Doug Schwarz on 4 Feb 2010 11:21 In article <hkeq9g$k5e$1(a)fred.mathworks.com>, "Juliette Salexa" <juliette.physicist(a)gmail.com> wrote: > Hello, > > I was wondering if there's a neat/efficient way to generate > the matrix: > > [1 2 3 4 5 ; > 0 1 2 3 4 ; > 0 0 1 2 3 ; > 0 0 0 1 2 ; > 0 0 0 0 1 ] > > using only the vector: > > [1 2 3 4 5] > > The way I'm doing it right now uses CIRCSHIFT, but it seems like there must > be a much more scalable and neat way to do this, > > any suggestions ?? > > Thank you! > juliette triu(toeplitz([1 2 3 4 5])) -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address.
From: Juliette Salexa on 4 Feb 2010 12:08 WOWWW! Thank you Doug! > triu(toeplitz([1 2 3 4 5])) > > -- > Doug Schwarz > dmschwarz&ieee,org > Make obvious changes to get real email address.
From: Jos (10584) on 4 Feb 2010 15:09 "Juliette Salexa" <juliette.physicist(a)gmail.com> wrote in message <hkeuti$1oq$1(a)fred.mathworks.com>... > WOWWW! > > Thank you Doug! > > > > > triu(toeplitz([1 2 3 4 5])) and its sibling: B = [10 11 12 13 14] ; fliplr(hankel(B(end:-1:1))) % or even ... triu(B(max(cumsum(triu(ones(numel(B))),2),1))) Jos
From: Matt J on 4 Feb 2010 15:54 "Jos (10584) " <#10584(a)fileexchange.com> wrote in message <hkf9gv$sd5$1(a)fred.mathworks.com>... > "Juliette Salexa" <juliette.physicist(a)gmail.com> wrote in message <hkeuti$1oq$1(a)fred.mathworks.com>... > > WOWWW! > > > > Thank you Doug! > > > > > > > > > triu(toeplitz([1 2 3 4 5])) > > and its sibling: > > B = [10 11 12 13 14] ; > fliplr(hankel(B(end:-1:1))) > % or even ... > triu(B(max(cumsum(triu(ones(numel(B))),2),1))) ====================== Why not just the following one-liner? toeplitz([1 0 0 0 0],[1 2 3 4 5])
|
Pages: 1 Prev: How to capture the undefined input argument... Next: size differ |