"At least one 'end' is missing: the statement may begin here"
    7 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
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
0 Kommentare
Antworten (1)
  stozaki
    
 am 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 Kommentare
  stozaki
    
 am 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
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!