フィルターのクリア

ismember: how to read the results quicker?

2 ビュー (過去 30 日間)
wesleynotwise
wesleynotwise 2017 年 6 月 3 日
コメント済み: wesleynotwise 2017 年 6 月 3 日
Hello. I would like to know how to return real values instead of logical values when the 'ismember' is used? eg:
A = [1 2 3 4 5];
B = [6 7 4 5 9 10 11 12];
ismember (A,B)
ans =
1×5 logical array
0 0 0 1 1
Is it possible to have this as output?
[4 5]

採用された回答

Stephen23
Stephen23 2017 年 6 月 3 日
編集済み: Stephen23 2017 年 6 月 3 日
find(ismember(...))
Keep in mind that logical indexing is more efficient for simple indexing tasks, so the answer to the question posed in your title "ismember: how to read the results quicker?" is actually to do the opposite of what you asked: just use logical indexing, and not subscript indexing (and especially not waste time using find).
  1 件のコメント
wesleynotwise
wesleynotwise 2017 年 6 月 3 日
C001. Thank you :)

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2017 年 6 月 3 日
Stephen's answer assumed A was of the form 1:N.
A = [5 4 3 2 1];
B = [6 7 4 5 9 10 11 12];
loc = ismember(A, B)
find(loc)
A(loc)
Use the output from ismember to index back into A to retrieve the elements of A that are in B.
  1 件のコメント
wesleynotwise
wesleynotwise 2017 年 6 月 3 日
Thanks for the suggestion, Steven.

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by