Filter löschen
Filter löschen

help on if statement

1 Ansicht (letzte 30 Tage)
Abra dog
Abra dog am 1 Nov. 2011
How can I use a if loop to display where X4(n,1)>X4(n,2)>X4(n,3)>X4(n,4)>X4(n,5) == 1 n = 1:31 I want it to show where this is true in the matrix or should i use a while loop?
  1 Kommentar
Walter Roberson
Walter Roberson am 8 Dez. 2011
There is no such thing as an if loop.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Honglei Chen
Honglei Chen am 1 Nov. 2011
You can vectorize this in one command:
idx = 1:31;
find( (X4(idx,1)>X4(idx,2))&(X4(idx,2)>X4(idx,3))&(X4(idx,3)>X4(idx,4))&(X4(idx,4)>X4(idx,5))&(X4(idx,5)==1))
HTH
  2 Kommentare
Abra dog
Abra dog am 1 Nov. 2011
It says Empty matrix: 0-by-1
Abra dog
Abra dog am 1 Nov. 2011
Never mind found out what i was doing wrong with your command. I don't need to put ==1 at the end. Thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by