How to implement more steps in mathwork coding?
이전 댓글 표시
fun [ …… 0ut2 …. ]= mainfun [………………….]
iteration=0
while iteration<maxiterationno
some parameter and their calculation
iteration=iteration+1
[ ]=subfun1 [];
[ ,out2 ]= subfun2[];
if iteration == 1
% at the first iteration save the result
B = out2;
else
% for all other iterations, check if the new result is bigger
if sum( B(:,c) ) < sum( out2(:,c) )
% if so break the loop
break
end
end
Newoutput=out2(1:10,:)
end
end
By doing this I am getting my generation number with my expected value ,but i want to do another further steps like ,
when my previous condition match that time i want to keep the value of the out2 and want to do another few iteration and everytime i want to compare with the new iteration value with the out2 value .
like maybe i got the expected out2 value at iteration number 100 , so i will keep the value of out2 as constant and will do the next few iteration and everytime i will compare the value with different iteration means 101th iteration with 100 iteration or 102 iteration value with 100 iteration value where out2 value will be constant after 100th iteration when the first condition will match and then it will continue maybe another 3 to 5 iteration .
then i want to stop my iteration .
Thank you in advance .
채택된 답변
추가 답변 (1개)
Maybe:
fun [ …… 0ut2 …. ]= mainfun [………………….]
iteration=0
while iteration < maxiterationno
...
if iteration == 1 % at the first iteration save the result
B = out2;
else % for all other iterations, check if the new result is bigger
if sum( B(:,c) ) < sum( out2(:,c) )
% break - no, don't break the loop, but:
maxiterationno = iteration + 5;
B = out2;
end
end
end
댓글 수: 7
Akash Pal
2022년 11월 14일
Jan
2022년 11월 14일
"but i want the iteration number where my loop is ending and i am getting the expected result" - This does not contain enough information to suggest a solution.
If the wanted ondition sum(B(:,c)) < sum(out2(:,c)) is met, the number of iterations should not reach 1000 anymore, because this code limits maxiterationno to iteration+5.
Jan
2022년 11월 14일
As far as I understand, you explain the behaviour of the posted function.
Then what do you want to change?
Akash Pal
2022년 11월 15일
Jan
2022년 11월 15일
Yes. Exactly this is done by my code, isn't it?
Akash Pal
2022년 11월 16일
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!