From: Juliette Salexa on
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
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
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
"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
"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])