Tuesday, June 16, 2009

Matlab: find row vector within matrix.

OP here.

Q:

Say I have a matrix:

x = [
11 22 33
44 55 66
11 11 11
33 99 33
11 77 23]


I want to find a specific row in it, say y = [11 11 11].


A1:
You can use ismember with parameter "rows".

A2:
To allow some tolerance:

% engine;
locrow = @(A,x,tol)find(sum(abs(bsxfun(@minus,A,x)),2) <= tol)

% usage;
tol = 0.01
locrow(A,[11.0001, 11.0001, 10.9999], tol)

4 comments:

Unknown said...
This comment has been removed by the author.
altered said...

I found your post very useful! I was trying to find a way of doing exactly what you described, and used the ismember() function to achieve the desired result.

Thank you for the post.

overmindxp said...

Thanks for the ismember tip. Worked like a charm.

Philipp said...

but much too slow. craplab