Finding a needle in a matrix

조회 수: 1 (최근 30일)
012786534
012786534 2017년 4월 12일
댓글: 012786534 2017년 4월 12일
Hello,
Let's say I have a 10 x 10 matrix filled with numbers (10 X 10 double) which can only be 1, 2 or 3. I need a code that returns an error if there's any other number in there, like say a 4 or an 8. I would have thought that:
if Y ~=1|Y ~=2|Y ~=3
disp('error')
return,
end
would work but it always returns an error message. Any ideas?
Thank you

채택된 답변

the cyclist
the cyclist 2017년 4월 12일
편집: the cyclist 2017년 4월 12일
if not(all(ismember(Y(:),[1 2 3])))
disp('error')
end
  댓글 수: 1
012786534
012786534 2017년 4월 12일
That's great! Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by