In the below script, based on iteration numbers in for loop, I need to change Y_10, Y_20,Y_30,Y_40.....Y_100
Is there a way to achive this instead of renaming everytime ??
saveas(gcf, sprintf('Y_10mm'), 'bmp')
savefig(gcf, sprintf('Y_10mm')

 채택된 답변

DGM
DGM 2022년 4월 27일
편집: DGM 2022년 4월 27일

0 개 추천

In whatever loop you're using, create the filename something like this:
k = 10 % whatever number you need
k = 10
sprintf('Y_%03dmm.bmp',k)
ans = 'Y_010mm.bmp'
Unless you have a need to avoid it, zero-pad your numbers so that your files sort correctly and are easier to read back in corresponding order

댓글 수: 6

Thanks...
Hi,
Incase, if have something like this Y_10mm_X_20mm, here basically I need to change both X and Y values
Any suggestions please ??
saveas(gcf, sprintf('Y_10mm_X_20mm'), 'bmp')
You can add more something like so.
h = 10; % for example
w = 20;
sprintf('Y_%03dmm_x_%03dmm.bmp',h,w)
ans = 'Y_010mm_x_020mm.bmp'
Got it!! Thank you very much..
KHAING
KHAING 2024년 11월 3일
how about repeat in for loop for many series number of figure
for h = [10 20 30]
for w = [20 21 22]
filename = sprintf('Y_%03dmm_x_%03dmm.bmp',h,w);
%some calculation
imwrite(YourImage, filename);
end
end

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

추가 답변 (0개)

카테고리

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

질문:

2022년 4월 27일

댓글:

2024년 11월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by