フィルターのクリア

Plot index of for loop

5 ビュー (過去 30 日間)
kale
kale 2023 年 4 月 22 日
編集済み: chicken vector 2023 年 4 月 22 日
I have a for loop that plots a graph that dynamically updates (don't look at the what the code does and what it plots, it doesn't matter).
I would like to print simultaneously with the dynamic plot (generated with "plot" and "drawnow") the index "i" of the loop, to see what index that given iteration/plot corresponds to.
I think the sprintf function should be used, but anyway if another function should be used tell me. I did some tests with sprintf but could not produce the result I hoped for
I am attaching the code, if you want to update it or tell me how I can solve this problem .. thank you in advance!

採用された回答

chicken vector
chicken vector 2023 年 4 月 22 日
編集済み: chicken vector 2023 年 4 月 22 日
I used annotation because accepts normalised units, otherwise text might be a better option. Have a look at it.
Also I stronlgy suggest you to avoid naming variables with function names, such as length.
Finally, unless needed for demonstration purposes, avoid live scripts and use normal scripts.
By doing so you can initialise a figure outside the loop, instead of setting the same figure title at each iteration with title('dynamic graph'); inside the loop.
for i=1:length %ciclo for 200 giri
in=circshift(in,1);
in(1)=seq(i);
ff = sum(in.*variable_f);
if i>n
e = ff - seq(i-n);
variable_f= variable_f - step*e*conj(in);
end
plot(variable_f)
% Command to show current iteration (add this to your loop):
iteration = annotation('textbox', [.7 .7 .1 .1], ...
'EdgeColor', 'None', ...
'String', [num2str(i) '/' num2str(length)], ...
'FontSize',20);
drawnow
title('dynamic graph');
end

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by