필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by