필터 지우기
필터 지우기

Using text function in a for loop

조회 수: 23 (최근 30일)
Raldi
Raldi 2012년 5월 12일
Hi, what i want to ask is how can i use the text function inside a loop and make it print the number of iterations? like this
for i = 1:4
----some code----
text(pos1,pos2,i)
end
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 5월 12일
Where do you want it printed? If on a graph, then you're on the right track. Do you want to keep the iteration already printed or you want to update it?
If you want to print it in the command window use disp or sprintf.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 5월 12일
Don't use i (the imaginary variable) for your loop index.
I handle a number of situations below.
for k = 1:1000
caption = sprintf('The value of k is %d', k);
% Print to command window.
fprintf('%s\n', caption);
% Print to static text control on a GUI.
set(handleToText, 'String', caption);
% Print to the overlay of an image or plot.
text(5, 10, caption);
% Force it to repaint the screen immediately.
drawnow;
end
Note the use of drawnow. If you're in an intensive loop, it often won't take time out to repaint your GUI until it's done with the loop. Thus you won't see any update on your screen. To get around this, use the drawnow command to force it to update/refresh/repaint the screen each time it's called.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by