"At least one 'end' is missing: the statement may begin here"

5 vues (au cours des 30 derniers jours)
Cole Bromfield
Cole Bromfield le 13 Jan 2020
Commenté : stozaki le 13 Jan 2020
k=1
for k=1:20
disp(k)
if mod(k,2)==0
disp("na")
if mod(k,3)==0
disp("ba")
if mod(k,5)==0
disp("mo")
else
disp("gano")
end
end

Réponses (1)

stozaki
stozaki le 13 Jan 2020
Please try following script.
k=1
for k=1:20
disp(k)
if mod(k,2)==0
disp("na")
elseif mod(k,3)==0
disp("ba")
elseif mod(k,5)==0
disp("mo")
else
disp("gano")
end
end
Regards,
stozaki
  2 commentaires
Cole Bromfield
Cole Bromfield le 13 Jan 2020
I need it to display every syllable that applies though. For example, if a number is divisible by both 2 and 5, I need "namo" to be displayed. With that code, it just displays "na"
stozaki
stozaki le 13 Jan 2020
How about using the highest priority decision in the if clause?
k=1
for k=1:20
disp(k)
if mod(k,5)==0 && mod(k,2)==0
disp("namo")
elseif mod(k,3)==0
disp("ba")
elseif mod(k,5)==0
disp("mo")
elseif mod(k,2)==0
disp("na")
else
disp("gano")
end
end
Regards
stozaki

Connectez-vous pour commenter.

Catégories

En savoir plus sur Reporting and Database Access dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by