Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Can anyone help me to change this if else looping into for looping ?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!