Filter löschen
Filter löschen

How to say not equals to for 3 variables

14 Ansichten (letzte 30 Tage)
Avishka Karunaratne
Avishka Karunaratne am 22 Feb. 2016
Kommentiert: John D'Errico am 22 Feb. 2016
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

Antworten (2)

John D'Errico
John D'Errico am 22 Feb. 2016
Bearbeitet: John D'Errico am 22 Feb. 2016

How about:

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

or...

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

or many other ways.

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

Melden Sie sich an, um zu kommentieren.


Azzi Abdelmalek
Azzi Abdelmalek am 22 Feb. 2016
Bearbeitet: Azzi Abdelmalek am 22 Feb. 2016
a~=b & a~=c
%or you can use ismember function
~ismember(a,[b,c])
  3 Kommentare
Avishka Karunaratne
Avishka Karunaratne am 22 Feb. 2016
How do I do it then ?
John D'Errico
John D'Errico am 22 Feb. 2016
Bearbeitet: John D'Errico am 22 Feb. 2016
Read my answer as to how to do it. There I gave two ways of solving the problem that are NOT subject to failure.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by