Prev: In Level 2 m-file s-function, can the dimension of vector Dwork be set dynamically?
Next: Time shift and FFT
From: AlexHuber Huber on 8 Apr 2010 06:14 Hi, I have got Matrix A and I want to save the upper triangular part of the Matrix A in a vector b. For example A=[1,2,3;4,5,6;7,8,9] then then function should do the following: function(A)=[1;2;3;5;6;9] I know how to do it with a for loop, but I feel there are far easier solutions :) (I need this to fit a VAR on a matrix) Thanks, Michael
From: mikin Nede on 8 Apr 2010 06:34 "AlexHuber Huber" <mischamail(a)web.de> wrote in message <hpka9e$561$1(a)fred.mathworks.com>... Hi Alex, just do it: nonzeros(triu(A)') Cheers, Mik
From: AlexHuber Huber on 8 Apr 2010 06:47 "mikin Nede" <mnedelj(a)gmail.com> wrote in message <hpkbet$l4m$1(a)fred.mathworks.com>... > "AlexHuber Huber" <mischamail(a)web.de> wrote in message <hpka9e$561$1(a)fred.mathworks.com>... > Hi Alex, just do it: > > nonzeros(triu(A)') > > Cheers, > Mik Wow that works, thanks very nice!
From: Bruno Luong on 8 Apr 2010 06:52 > > nonzeros(triu(A)') > This won't work if the upper triangular part has zero(s). Use this tool: http://www.mathworks.com/matlabcentral/fileexchange/23391-triangular-and-diagonal-indexing Bruno
From: vortse a on 8 Apr 2010 08:32 You can use triu on a logical matrix and avoid using nonzeros: >>B=A(triu(true(size(A)))) However this aggregates B columnwise. If this is unwanted, then there is some transposing to be done, but I was unable to conjure it.
|
Next
|
Last
Pages: 1 2 Prev: In Level 2 m-file s-function, can the dimension of vector Dwork be set dynamically? Next: Time shift and FFT |