Make the FIND more compact

1 次查看(过去 30 天)
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;

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by