How to vectorize if statement

5 Ansichten (letzte 30 Tage)
Master Blabla
Master Blabla am 19 Nov. 2020
Bearbeitet: Master Blabla am 19 Nov. 2020
How to vectorize this if statement
f = 0;
if(m < 7)
if(m < sm*0.3)
f = 5;
end
end
  1 Kommentar
James Tursa
James Tursa am 19 Nov. 2020
What is m and sm? What do you actually want as a result for f? You don't show a loop so I am not sure what you want vectorized.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

David Hill
David Hill am 19 Nov. 2020
Looks like f is just a scalar. No vectorization needed.
if m<7&&m<sm*.3
f=aSortI(1);
else
f=0;
end

Weitere Antworten (1)

Setsuna Yuuki.
Setsuna Yuuki. am 19 Nov. 2020
you can try:
[aSortV,aSortI] = sort(c,'ascend');
f = 0;
if(m < 7 && m < sm*0.3)
f = aSortI(1);
end

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