From: Ulrik Nash on 8 Jul 2010 07:18 Hi Everyone, Suppose I have a matrix A = [1 3 4 6; 10 9 30 23] now I wish to perform an operation, so that I create B = [3 9] Note that B contains the column of A where the second row value is smallest. How is this done? Ulrik.
From: Oleg Komarov on 8 Jul 2010 08:31 "Ulrik Nash" <uwn(a)sam.sdu.dk> wrote in message <i14c5h$b73$1(a)fred.mathworks.com>... > Hi Everyone, > > Suppose I have a matrix > > A = [1 3 4 6; 10 9 30 23] > > now I wish to perform an operation, so that I create > > B = [3 9] > > Note that B contains the column of A where the second row value is smallest. > > How is this done? > > Ulrik. B = A(:,min(A(2,:)) == A(2,:)).' Oleg
From: dpb on 8 Jul 2010 08:39 Ulrik Nash wrote: > Hi Everyone, > > Suppose I have a matrix > A = [1 3 4 6; 10 9 30 23] > > now I wish to perform an operation, so that I create > > B = [3 9] > > Note that B contains the column of A where the second row value is > smallest. > > How is this done? [dum,idx]=min(A(2,:)); B=A(:,idx); --
From: Ulrik Nash on 8 Jul 2010 08:44 "Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <i14ge9$90c$1(a)fred.mathworks.com>... > "Ulrik Nash" <uwn(a)sam.sdu.dk> wrote in message <i14c5h$b73$1(a)fred.mathworks.com>... > > Hi Everyone, > > > > Suppose I have a matrix > > > > A = [1 3 4 6; 10 9 30 23] > > > > now I wish to perform an operation, so that I create > > > > B = [3 9] > > > > Note that B contains the column of A where the second row value is smallest. > > > > How is this done? > > > > Ulrik. > > B = A(:,min(A(2,:)) == A(2,:)).' > > Oleg Thanks Oleg, much appreciated!
From: Steven Lord on 8 Jul 2010 09:24 "dpb" <none(a)non.net> wrote in message news:i14h3i$hk7$1(a)news.eternal-september.org... > Ulrik Nash wrote: >> Hi Everyone, >> >> Suppose I have a matrix >> A = [1 3 4 6; 10 9 30 23] >> >> now I wish to perform an operation, so that I create >> >> B = [3 9] >> >> Note that B contains the column of A where the second row value is >> smallest. >> >> How is this done? > > [dum,idx]=min(A(2,:)); B=A(:,idx); I just want to call out, in case the OP didn't notice this, that Oleg's solution will return _all_ columns that have the second row's minimum value in their second row, while dpb's will contain only the first. Which is appropriate, or whether this makes any difference at all, depends on the OP's problem and data. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
Pages: 1 Prev: affine registration minimization with LTS Next: exange data with a simulink model from matlab |