From: Dimitar Dimitrov on
Hello,
I would like to generate an NxN matrix with the following structure (for N=6)

E = [0 1 2 3 4 5;
0 0 6 7 8 9;
0 0 0 10 11 12;
0 0 0 0 13 14;
0 0 0 0 0 15;
0 0 0 0 0 0];

Is there a way to do this without for loops?

Thanks,
Dimitar
From: Darren Rowland on
Try the following

E = triu(ones(6),1);
E(E==1) = 1:15

Hth,
Darren
From: Matt Fig on
"Darren Rowland" <darrenjremovethisrowland(a)hotmail.com> wrote in message <hl2agc$jkf$1(a)fred.mathworks.com>...
> Try the following
>
> E = triu(ones(6),1);
> E(E==1) = 1:15
>
> Hth,
> Darren



Or, rather

E = tril(ones(N),-1);
E(logical(E)) = 1:((N-1)*N/2);
E = E.'
From: Dimitar Dimitrov on
Hi
Thanks for the solution
Dimitar

> E = tril(ones(N),-1);
> E(logical(E)) = 1:((N-1)*N/2);
> E = E.'