If statement inside a while loop MATLAB
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to run an if else statement within a while loop but getting a syntax error: parse error near line 49 syntax error. Can someone help me identify and fix the syntax issue? Thanks!
rainfall_values=[39.9 31.0 42.3 42.1 41.1 28.7 16.8 34.1 56.4 48.7 44.1 42.8 48.4 34.2 32.4 46.4 38.9 37.3 50.6 44.8 34.0 45.6 37.3 43.7 41.8 41.1 31.2 35.2 35.1 49.3 44.2 41.7 30.8 53.6 34.5 50.3 43.8 21.6 47.1 31.2 27.0 37.0 46.8 26.9 25.4 23.0 56.5 43.4 41.3 46.0 44.3 37.8 29.6 35.1 49.7 36.6 32.5 61.7 47.4 33.9 31.7 31.5 59.6 50.5 38.6 43.4 28.7 32.0 51.8]
j=1;
v5_10=0;
v10_15=0;
v15_20=0;
v20_25=0;
v25_30=0;
v30_35=0;
v35_40=0;
v40_45=0;
v45_50=0;
v50_55=0;
v55_60=0;
v60_65=0;
i=0;
while j<=69
i=rainfall_values(j);
if i<10
v5_10=v5_10+1;
else if i<15
v10_15=v10_15+1;
else if i<20
v15_20=v15_20+1;
else if i<25
v20_25=v20_25+1;
else if i<30
v25_30=v25_30+1;
else if i<35
v30_35=v30_35+1;
else if i<40
v35_40=v35_40+1;
else if i<45
v40_45=v40_45+1;
else if i<50
v45_50=v45_50+1;
else if i<55
v50_55=v50_55+1;
else if i<60
v55_60=v55_60+1;
else
v60_65=v60_65+1;
end
j=j+1;
end
0 Kommentare
Antworten (1)
Dave B
am 4 Nov. 2021
All of those else if should be elseif.
rainfall_values=[39.9 31.0 42.3 42.1 41.1 28.7 16.8 34.1 56.4 48.7 44.1 42.8 48.4 34.2 32.4 46.4 38.9 37.3 50.6 44.8 34.0 45.6 37.3 43.7 41.8 41.1 31.2 35.2 35.1 49.3 44.2 41.7 30.8 53.6 34.5 50.3 43.8 21.6 47.1 31.2 27.0 37.0 46.8 26.9 25.4 23.0 56.5 43.4 41.3 46.0 44.3 37.8 29.6 35.1 49.7 36.6 32.5 61.7 47.4 33.9 31.7 31.5 59.6 50.5 38.6 43.4 28.7 32.0 51.8]
j=1;
v5_10=0;
v10_15=0;
v15_20=0;
v20_25=0;
v25_30=0;
v30_35=0;
v35_40=0;
v40_45=0;
v45_50=0;
v50_55=0;
v55_60=0;
v60_65=0;
i=0;
while j<=69
i=rainfall_values(j);
if i<10
v5_10=v5_10+1;
elseif i<15
v10_15=v10_15+1;
elseif i<20
v15_20=v15_20+1;
elseif i<25
v20_25=v20_25+1;
elseif i<30
v25_30=v25_30+1;
elseif i<35
v30_35=v30_35+1;
elseif i<40
v35_40=v35_40+1;
elseif i<45
v40_45=v40_45+1;
elseif i<50
v45_50=v45_50+1;
elseif i<55
v50_55=v50_55+1;
elseif i<60
v55_60=v55_60+1;
else
v60_65=v60_65+1;
end
j=j+1;
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!