How to store values of iterations during a for loop?

2 ビュー (過去 30 日間)
Yro
Yro 2021 年 5 月 16 日
回答済み: Madhav Thakker 2021 年 5 月 18 日
I have the following problem, I have three for loops, and I need to store the number of iterations that correspond to the second for loop, to show its total during the execution of the main loop. For example:
% Initialization
for i = 1:npop % first loop / npop = 600
(something
end
% Iterations
for it = 1:iters % Main loop / iters = 100
(something)
for l = 1:nc % third loop / obj function evaluation / nc = 600
(something)
end
end
In the first loop npop = 600, in the second iters = 100 and in the third nc = 600. If anyone has experience what I am doing is a genetic algorithm in which I want to show the number of objective function evaluations.
Thanks in advance.
  1 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 5 月 16 日
hello
if you use for loops , that means you execute the loop until the last iteration index , so the total number of iterations of the second for loop is already known (as you specifiy it)
if you would use while lopps that's a different story

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

採用された回答

Madhav Thakker
Madhav Thakker 2021 年 5 月 18 日
Hi Yro,
Have a look at for loop documentation in MATLAB to know how it works.
Open this example in MATLAB command window to run and display values in each iteration.
openExample('matlab/ExecuteStatementsForSpecifiedValuesExample')
Hope this helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by