For Programmers: Free Programming Magazines  


Home > Archive > Matlab > December 2006 > find command









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author find command
amir

2006-12-26, 8:14 am

Hi all!
I have a position matrix "P" which is 3-by-n (3-D space). and also I
have point position in space(3-by-1). I need to know which column in
P is match with this point.
when P is 1-by-n I can do that using "find" command(1 dimensional
space). But find command can not find a column in P. any one can help?
us

2006-12-26, 8:14 am

amir:
<SNIP wants to find matching cols in a mat...

one of the many solutions

% the data
m=rand(3,7); % cloud of points
p=rand(3,1); % a point to match
m(:,[2,4])=[p,p]; % inserted twice...
% the engine
lx=strfind(m(:).',p.');
[col,col]=ind2sub(size(m),lx);
% the result
col
% col = 2 4

us
us

2006-12-26, 8:14 am

us:
<SNIP an ok but potentially premature solution...

....just in case some of your coordinates are not unique

% data with some anomalies
m=ones(3,6);
p=ones(3,1);
% the engine
lx=strfind(m(:).',p.');
[row,col]=ind2sub(size(m),lx);
col=col(row==1);
% the (expected) result
col
% col = 1 2 3 4 5 6

us
amir

2006-12-26, 7:17 pm

Thanks for your help. I applied it to my model.
Amir
us wrote:
>
>
> us:
> <SNIP an ok but potentially premature solution...
>
> ...just in case some of your coordinates are not unique
>
> % data with some anomalies
> m=ones(3,6);
> p=ones(3,1);
> % the engine
> lx=strfind(m(:).',p.');
> [row,col]=ind2sub(size(m),lx);
> col=col(row==1);
> % the (expected) result
> col
> % col = 1 2 3 4 5 6
>
> us

daniel_nordlund_1982@hotmail.com

2006-12-26, 7:17 pm

amir skrev:
> Hi all!
> I have a position matrix "P" which is 3-by-n (3-D space). and also I
> have point position in space(3-by-1). I need to know which column in
> P is match with this point.
> when P is 1-by-n I can do that using "find" command(1 dimensional
> space). But find command can not find a column in P. any one can help?


Use find on each dimension and 'and' the result. So for matrix P and
point x do this:

find(P(1,:)==x(1) & P(2,:)==x(2) & P(3,:)==x(3))

Daniel

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com