How to say not equals to for 3 variables

19 次查看(过去 30 天)
I want to set the condition in my if loop for which , if a is not equal to b and not equal to c then do ... how do i do this a ~= b ~= c does not work

回答(2 个)

John D'Errico
John D'Errico 2016-2-22
编辑:John D'Errico 2016-2-22

How about:

a~=b && a~=c && b~=c

or...

numel(unique([a,b,c])) == 3

or many other ways.

  3 个评论
Stephen23
Stephen23 2016-2-22
@Avishka Karunaratne: correct.
@John D'Errico: +1 for the nice answer.
John D'Errico
John D'Errico 2016-2-22
Yes. The nice thing about using unique here is it makes the test easy, for any number of variables.

请先登录,再进行评论。


Azzi Abdelmalek
Azzi Abdelmalek 2016-2-22
编辑:Azzi Abdelmalek 2016-2-22
a~=b & a~=c
%or you can use ismember function
~ismember(a,[b,c])
  3 个评论
John D'Errico
John D'Errico 2016-2-22
编辑:John D'Errico 2016-2-22
Read my answer as to how to do it. There I gave two ways of solving the problem that are NOT subject to failure.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by