フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Muhammad Hafiz
Muhammad Hafiz 2017 年 12 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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
  1 件のコメント
Rena Berman
Rena Berman 2017 年 12 月 26 日
(Answers Dev) Restored edit

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 12 月 4 日
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 件のコメント
Muhammad Hafiz
Muhammad Hafiz 2017 年 12 月 4 日
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 :(

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by