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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Voss
Voss le 30 Juin 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

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by