Finding a needle in a matrix
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
the cyclist
2017-4-12
编辑:the cyclist
2017-4-12
if not(all(ismember(Y(:),[1 2 3])))
disp('error')
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!