if-elseif-else statement take turns/used each of them in while loop, how to write properly?

1 Ansicht (letzte 30 Tage)
Hello, im new in MATLAB, and here's my problem: the while loop should be run at sometime, while each loop should take the if statement sequentially (while loop do work> take if statement>second loop>take elseif > 3rd loop> take else> 4th loop> if statement> and so on) i kinda new to use some of the feature like rem feature. Could you give me some guidance? thanks :)
i=1
a(i)=0
while true
i = i+1
a(i) = a(i-1) +1
if a==1:3:15
disp('its first num')
elseif a== 2:3:15
disp('its sec num')
else a==3:3:15
disp('its 3rd num')s
end
if a > 20
break
end
end

Akzeptierte Antwort

Voss
Voss am 30 Jun. 2022
Like this?
i=0;
while i <= 20
i = i+1;
r = rem(i,3);
if r == 1
disp('its first num')
elseif r == 2
disp('its sec num')
else
disp('its 3rd num')
end
end
its first num
its sec num
its 3rd num
its first num
its sec num
its 3rd num
its first num
its sec num
its 3rd num
its first num
its sec num
its 3rd num
its first num
its sec num
its 3rd num
its first num
its sec num
its 3rd num
its first num
its sec num
its 3rd num

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by