How to use use = logical operator on multiple values?
26 次查看(过去 30 天)
显示 更早的评论
For example if I had vector A = [1,5,8,2,6,4,3];
And I want to check if A equal to 1st value, 2nd value or 4th value
istead of doing:
A1 = (A == A(1))| (A == A(2)) | (A == A(4))
Is there a shorter way, so like: A1 == A(1,2,4)
idk how to explain soz
2 个评论
Ameer Hamza
2020-4-21
Koki, can you explain with a clear example. What does the statement "A equal to 1st value, 2nd value or 4th value" means? A is a vector, and its elements are scalar? How do you want to compare?
采纳的回答
Mohammad Sami
2020-4-21
As suggested by stephen, you can simply use ismember
A1 = ismember(A,A([1 2 4]));
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!