How to make an efficient if-statement-expression that when identifying a 1x3 vector consisting only of either 6's,7's,8's or 9's gives the same statement?
이전 댓글 표시
I could you run following if statement
vec=[9 9 9]; if vec(1:3)==9 | vec(1:3)==8 | vec(1:3)==7 | vec(1:3)==6 disp('Identified') end Identified
But is there not a more efficient way to accomplish this in stead of writing all these 'or-signs' in the if statement? With vectorized code? I have tried with a for loops, but got problems when writing it under an if statement with more than one evaluation option like elseif
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2012년 11월 22일
x = unique(vec);
out = numel(x) == 1 && ismember(x, 6:9);
카테고리
도움말 센터 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!