From: Dimitar Dimitrov on 11 Feb 2010 18:08 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 11 Feb 2010 20:22 Try the following E = triu(ones(6),1); E(E==1) = 1:15 Hth, Darren
From: Matt Fig on 11 Feb 2010 21:29 "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 12 Feb 2010 04:35 Hi Thanks for the solution Dimitar > E = tril(ones(N),-1); > E(logical(E)) = 1:((N-1)*N/2); > E = E.'
|
Pages: 1 Prev: Is there an "about equal" function? Next: simulink memory problem |