Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Can anyone help me to change this if else looping into for looping ?

1 Ansicht (letzte 30 Tage)
Muhammad Hafiz
Muhammad Hafiz am 4 Dez. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
maxit = 1000;
wmax = 1.2;
wmin = 0.4;
for it=1:maxit
if it <= 75
w = wmax+(-1*(wmax-wmin)*it/75);
elseif it <= 150
w = wmin+(1*(wmax-wmin)*(it-75)/150); % jarak 75
elseif it <= 225
w = wmax+(-1*(wmax-wmin)*(it-75)/150);
elseif it <= 290
w = wmin+(1*(wmax-wmin)*(it-225)/215); % jarak 65
elseif it <= 355
w = wmax+(-1*(wmax-wmin)*(it-140)/215);
elseif it <= 410
w = wmin+(1*(wmax-wmin)*(it-355)/270); % jarak 55
elseif it <= 465
w = wmax+(-1*(wmax-wmin)*(it-195)/270);
elseif it <= 510
w = wmin+(1*(wmax-wmin)*(it-465)/315); % jarak 45
elseif it <= 555
w = wmax+(-1*(wmax-wmin)*(it-240)/315);
elseif it <= 590
w = wmin+(1*(wmax-wmin)*(it-555)/350); % jarak 35
elseif it <= 625
w = wmax+(-1*(wmax-wmin)*(it-275)/350) ;
elseif it <= 650
w = wmin+(1*(wmax-wmin)*(it-625)/375); % jarak 25
elseif it <= 675
w = wmax+(-1*(wmax-wmin)*(it-300)/375);
elseif it <= 690
w = wmin+(1*(wmax-wmin)*(it-675)/390); % jarak 15
elseif it <= 705
w = wmax+(-1*(wmax-wmin)*(it-315)/390);
end
end

Antworten (1)

Walter Roberson
Walter Roberson am 4 Dez. 2017
It is already for looping. if/else is not looping.
You could rewrite like,
for it = 1 : 75
w = wmax+(-1*(wmax-wmin)*it/75);
end
for it = 76 : 150
w = wmin+(1*(wmax-wmin)*(it-75)/150); % jarak 75
end
for it = 151 : 225
w = wmax+(-1*(wmax-wmin)*(it-75)/150);
end
and so on. There are other ways to write the code as well.
  1 Kommentar
Muhammad Hafiz
Muhammad Hafiz am 4 Dez. 2017
sorry my bad english ,,, yes, I mean I want to change if/else condition into for looping ,,, because there are so many condition hard to set :(

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by