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일

1 개 추천

M( ismember(B, Alert_LessThree) ) = 2

추가 답변 (1개)

Star Strider
Star Strider 2017년 7월 11일

2 개 추천

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!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2017년 7월 11일

댓글:

2017년 7월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by