フィルターのクリア

Make the FIND more compact

1 回表示 (過去 30 日間)
balandong
balandong 2017 年 7 月 11 日
コメント済み: balandong 2017 年 7 月 11 日
Hi Coder, Just out of curiosity, if we can make the last two lines into a single line?
M = zeros (9,1);
Alert_LessThree = 1:3;
B = [2 4 4 4 1 5 6 7 8];
[tf,Ioc_Alert_LessThree] = find (ismember(B, Alert_LessThree));
M(Ioc_Alert_LessThree,:) = 2;
Thank you

採用された回答

Adam
Adam 2017 年 7 月 11 日
M( ismember(B, Alert_LessThree) ) = 2

その他の回答 (1 件)

Star Strider
Star Strider 2017 年 7 月 11 日
Yes.
You only need the first output from ismember, that is a logical vector. I believe this is the result you want:
M(ismember(B, Alert_LessThree)) = 2;
  1 件のコメント
balandong
balandong 2017 年 7 月 11 日
Thanks guys, in fact, that is more efficient!

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by