Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

1 visualización (últimos 30 días)
Muhammad Hafiz
Muhammad Hafiz el 4 de Dic. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Dic. de 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 comentario
Muhammad Hafiz
Muhammad Hafiz el 4 de Dic. de 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 :(

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by