フィルターのクリア

Find rows where one column value matches with any value inside another array

14 ビュー (過去 30 日間)
Anil Verma
Anil Verma 2016 年 8 月 7 日
回答済み: Star Strider 2016 年 8 月 7 日
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

採用された回答

Star Strider
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 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by