Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Voss
Voss il 30 Giu 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

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by