Call a certain function at the last iteration if flag is set to true
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
hmhuang
am 26 Nov. 2021
Beantwortet: Walter Roberson
am 26 Nov. 2021
I have a logic as following:
plot_final_iteration_only = true;
for iter = 1 : max_iter
% Do stuff...
if (plot_final_iteration_only)
if (iter == max_iter)
plotIteration(...);
end
else
plotIteration(...);
end
end
Is there any way to avoid writing plotIteration(...); for two times (which is a bit redundant for me), but with the same logic?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 26 Nov. 2021
plot_final_iteration_only = true;
for iter = 1 : max_iter
% Do stuff...
if ~plot_final_iteration_only || iter == max_iter
plotIteration(...);
end
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!