Hi,
I am trying to insert text to the series of images being generated for each iteration in for loop. For instance, lets say for f = 1:1:200, at f = 1 ieration i need to insert text of t = 0 s likewise t = 0.0002 s, t = 0.0004 s, t = 0.0006s for f = 2, 3, 4 ans so on respectively..
Please help me with this..

댓글 수: 2

KSSV
KSSV 2021년 5월 14일
Read about text.
I did tried as follows, but text getting overlapped on each image !!
for g = 0:0.00002:0.04
text(25,-35,['t= ',sprintf('%d',g)])
end

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

 채택된 답변

Rik
Rik 2021년 5월 14일
편집: Rik 2021년 5월 14일

0 개 추천

Instead of recreating graphics object every iteration of your loop, it is often faster to create the object once and then update the properties:
text_handle=text(25,-35,'');
for g = 0:0.00002:0.04
text_handle.String=sprintf('t= %.5f',g);
drawnow % force graphics update
end

댓글 수: 3

It just inserts t = 0 on each image, I guess it supposed to be like this ??
text_handle=text(25,-35,'');
for g = 0:0.00002:0.04
text_handle.String=sprintf('t= %d',g);
drawnow % force graphics update
end
Rik
Rik 2021년 5월 14일
편집: Rik 2021년 5월 14일
Ah, yes, sorry. I had at first set it print a 0 that way when initializing the object. I'll edit my answer. (you'll also have to change the FormatSpec to print the actual values, instead of telling Matlab to treat your values as integers)
Did this solve your question? If so, please consider marking it as accepted answer. If not, feel free to post a comment with your remaining issues.
Yes.. I have sorted the issue..
I am using as follows, now its better
t = 0.0002 * (i);
text(5,-35,[sprintf('t = %g s', t)],'FontSize',18,'Color','b','Interpreter','latex');

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 5월 14일

댓글:

2021년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by