I intend to insert text to each image saved during for loop operation.
I have for loop runs from i = 1:1:200 ;
lets say for image saved duirng i = 1 iteration I need to insert ' t = 0 s' and t = 0.0002 s, t = 0.0004 s, t = 0.0006 s for images saved duirng i = 2, 3, 4 iterations respectively. Please help me with this ...
for i = 1:1:200
%% image processing
%% insert text
%% save image
end

 채택된 답변

Turbulence Analysis
Turbulence Analysis 2021년 5월 14일

0 개 추천

Jan,
Thanks for your answer.
Actually, I am saving images in .bmp format as shown below.. Essentially for each iteration it saves image as S00001.bmp, S00002.bmp and so on...
for i = 1:1:100
%% save image to the folder
fname = fullfile(inputFolder, fname);
thisBaseFileName = sprintf('S%4.5d.bmp', i);
fullFileName = fullfile(outputFolder, thisBaseFileName);
saveas(gcf, fullFileName)
clf
end
And text should appear somewhere in the image like (x,y) = (10, -35) as shown in attached figure ..
text (10, -35, 'my text')

댓글 수: 3

Turbulence Analysis
Turbulence Analysis 2021년 5월 14일
Hi,
I tried as follows . I works well. But It prints on image as t = 2.000000e-4 s, But I just need to show t = 2e-4 s.. How to do that ??
text(10,-35,['t= ',sprintf('%ds',((i-1)*0.0002))],'FontSize',18,'Interpreter','latex');
Replace "['t= ',sprintf('%ds',((i-1)*0.0002))]" by
sprintf('t = %gs', (i-1) * 0.0002)
Hi,
Thanks for the correction..
I have used as follows, Now I am getting the intended one ...
t = 0.0002 * (i);
text(5,-35,[sprintf('t = %g s', t)],'FontSize',18,'Color','b','Interpreter','latex');

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

추가 답변 (1개)

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

1 개 추천

The question is not clear yet. Where should ' t = 0 s' appear? As title of an axes?
for i = 1:200
%% image processing
%% insert text
%% save image
t = 0.0002 * i;
FigH = figure;
axes;
title(sprintf('t = %g s', t));
% Now "save" the image
end
What does "save"! means here? Print as PDF, a screenshot, a fig file? Maybe:
savefig(FigH, sprintf('Figure%04d.fig', i), 'compact')

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by