Find rows where one column value matches with any value inside another array
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2016-8-7
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!