From: sumeet pushpam on
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
"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
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
"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
"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...