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]
|
|
|
| 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?
| |
|
| 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:
<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
| |
|
| 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
|
|
|
|
|