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?

 Akzeptierte Antwort

James Tursa
James Tursa am 19 Jul. 2017

0 Stimmen

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 Kommentare

Md. Tanjin Amin
Md. Tanjin Amin am 19 Jul. 2017
Thank you. I have understood. However, I can not get the desired output by modifying the code. Can you help please?
Md. Tanjin Amin
Md. Tanjin Amin am 19 Jul. 2017
Hi, I have solved the problem. Thank you.
fuad sharaf
fuad sharaf am 18 Mai 2020
How had you solved the problem?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-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