how to do the matrix value comparison of two different iterations ?

3 ビュー (過去 30 日間)
Akash Pal
Akash Pal 2022 年 6 月 22 日
コメント済み: Akash Pal 2022 年 11 月 4 日
fun [ …… …. ]= mainfun [………………….]
iteration=1
while iteration<maxiterationno
some parameter and their calculation
[ ]=subfun1 [];
[ ,out2 ]=subfun2[];
Newoutput=out2(1:10,:)
Iteration=iteration+1;
end
maybe from subfun2 I will get one output called out2 ,I want to do the comparison of iteration number i and iteration i+1 ,if iteration i+1 give me better solution like the summation of any specific column value is greater than the ith iteration then my iteration should be stop and it will show me the best solution value .

採用された回答

Karim
Karim 2022 年 6 月 22 日
yes, you can do this like you say by saving the best result and updating it at each iteration
i tried to update the pseudo code to give you the idea
function [] = mainfun()
iteration = 0;
old_out2 = 0;
c = 2; % column to check
while iteration < max_iteration
% increase the counter
iteration = iteration + 1;
% some parameter and their calculation
[] = subfun1();
[, out2] = subfun2();
if iteration == 1
% at the first iteration save the result
old_out2 = out2;
else
% for all other iterations, check if the new result is bigger
if sum( old_out2(:,c) ) < sum( out2(:,c) )
% if so break the loop
break
end
end
end
  4 件のコメント
Akash Pal
Akash Pal 2022 年 6 月 23 日
Thank You I understand .
Akash Pal
Akash Pal 2022 年 11 月 4 日
I have a question ,maybe after certain iteration number i got my expected result but if i want to do another 3 to 5 iteration more and if i get everytime better solution then i want to stop the iteration .Then how to implement inside the code ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by