From: sumeet pushpam on 10 May 2010 01:28 i have 'M', a 10X11 matrix having different elements. and now i have 'B' 1X11 matrix which i want to compare with each of M's 10 rows and find out which row it is closest to?? thanks
From: Roger Stafford on 10 May 2010 02:13 "sumeet pushpam" <sahil1806(a)gmail.com> wrote in message <hs85h5$c2j$1(a)fred.mathworks.com>... > i have 'M', a 10X11 matrix having different elements. > and now i have 'B' 1X11 matrix which i want to compare with each of M's 10 rows and find out which row it is closest to?? > > thanks You need to define what you mean by "closest" between 11-element rows. There are a number of different definitions of "distance" between vectors. Roger Stafford
From: sumeet pushpam on 10 May 2010 02:24 by closest i mean nearest. lets take an example.. say A= [ 1 2 3 ; 10 11 12; 20 21 22] a 3x3 matrix and B= [12 10 8], then i should get second row as the result of my question.sort of element by element comparison in each row. thanks.
From: Oleg Komarov on 10 May 2010 03:42 "sumeet pushpam" <sahil1806(a)gmail.com> wrote in message <hs88q5$9ji$1(a)fred.mathworks.com>... > by closest i mean nearest. lets take an example.. > > say A= [ 1 2 3 ; 10 11 12; 20 21 22] > a 3x3 matrix and > B= [12 10 8], then i should get second row as the result of my question.sort of element by element comparison in each row. > > thanks. % Find the absolue distance in an elementiwise row by row comparison: Clos = sum(abs(bsxfun(@minus, A,B)),2); Clos = 24.00 7.00 33.00 [val, row] = min(Clos); val = 7.00 row = 2.00 Is this what you're looking for? Oleg
From: sumeet pushpam on 10 May 2010 04:32
"Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <hs8dcd$1n9$1(a)fred.mathworks.com>... > "sumeet pushpam" <sahil1806(a)gmail.com> wrote in message <hs88q5$9ji$1(a)fred.mathworks.com>... > > by closest i mean nearest. lets take an example.. > > > > say A= [ 1 2 3 ; 10 11 12; 20 21 22] > > a 3x3 matrix and > > B= [12 10 8], then i should get second row as the result of my question.sort of element by element comparison in each row. > > > > thanks. > > % Find the absolue distance in an elementiwise row by row comparison: > Clos = sum(abs(bsxfun(@minus, A,B)),2); > Clos = > 24.00 > 7.00 > 33.00 > > [val, row] = min(Clos); > val = > 7.00 > row = > 2.00 > > Is this what you're looking for? > > Oleg yes !!.. thanks mate... |