필터 지우기
필터 지우기

Multiple Conditions with if

조회 수: 16 (최근 30일)
Md. Tanjin Amin
Md. Tanjin Amin 2017년 7월 19일
댓글: fuad sharaf 2020년 5월 18일
Hi,
I am having some problems. I need to apply 4 conditions and find out in which category each element of the input matrix falls. I am attaching the data file and matlab code which I wrote. The output result of first row of X supposed to be [3 4 1 4]. When I am running the code, the result is showing 1 for all elements in X matrix. Can anybody help please?

채택된 답변

James Tursa
James Tursa 2017년 7월 19일
MATLAB does not evaluate compound relational expressions like you are expecting. E.g., these lines
if D(i,j)<y(i,j)<G(i,j)
:
elseif D(i,j)>y(i,j)>H(i,j)
need to be a combination of two separate relational expressions:
if D(i,j)<y(i,j) && y(i,j)<G(i,j)
:
elseif D(i,j)>y(i,j) && y(i,j)>H(i,j)
  댓글 수: 3
Md. Tanjin Amin
Md. Tanjin Amin 2017년 7월 19일
Hi, I have solved the problem. Thank you.
fuad sharaf
fuad sharaf 2020년 5월 18일
How had you solved the problem?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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