필터 지우기
필터 지우기

How to say not equals to for 3 variables

조회 수: 14 (최근 30일)
Avishka Karunaratne
Avishka Karunaratne 2016년 2월 22일
댓글: John D'Errico 2016년 2월 22일
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
Avishka Karunaratne
Avishka Karunaratne 2016년 2월 22일
How do I do it then ?
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에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by