Find rows where one column value matches with any value inside another array
14 views (last 30 days)
Show older comments
I am new to Matlab, so please respond even if the question is trivial
I have a matrix. Lets say matrix is
A =[
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1]
I have an array. Lets say array is
B = [3, 6, 15]
I want to find out all the rows of Matrix A where column 3 value of Matrix A matches with any value mentioned in the array B. In the above case output will be
ans = [
16 2 3 13
9 7 6 12
4 14 15 1]
I don't want to use loop for this calculation. Is there any built in function which does this.
Thanks
0 Comments
Accepted Answer
Star Strider
on 7 Aug 2016
This works:
A =[16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1];
B = [3, 6, 15];
idx = ismember(A(:,3),B);
Result = A(idx,:)
Result =
16 2 3 13
9 7 6 12
4 14 15 1
0 Comments
More Answers (0)
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!