Problem in Using imwrite() Function

3 ビュー (過去 30 日間)
abhimanyu dubey
abhimanyu dubey 2020 年 7 月 27 日
コメント済み: abhimanyu dubey 2020 年 7 月 27 日
for i = 1 : 60000
name1 = [ 'something' , num2str(i) , '.tif' ] ;
pj = importdata(name1) ;
% do some processing on pj and then save it to new_fig
new_fig = pj ;
% Write Image Data to a File:
name2 = ['Output_File_' , num2str(i) , '.tif'] ; %%
imwrite(new_fig , name2) ;
end
Now the issue is that I want my file names like,
  • 'Outfile_File_00001'
  • 'Outfile_File_00010'
  • 'Outfile_File_00100'
  • 'Outfile_File_01000'
you get the idea.
This is required because for subsequent processing. So can anyone suggest me how to go about it. Please remember here, that the overall code is computationally intensive. So I don't want to use any if statments inside the loop. Can we solve this without making use of any if statments.
Thanks :)
  2 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 27 日
So you want the suffix to have all zeros except for a 1 in a certain location? But you have 60 thousand - you can't have a filename 60,000 characters long.
abhimanyu dubey
abhimanyu dubey 2020 年 7 月 27 日
No Sir, You got that wrong. What I want is to have:
  • For first 9 images: 'Outfile_File_000001' - 'Outfile_File_000009'
  • For 10th to 99th image: 'Outfile_File_000010' - 'Outfile_File_000099'
  • for 100 to 999 'Outfile_File_000100' - 'Outfile_File_000999'
  • for 1, 000 to 9,999 'Outfile_File_001000' - 'Outfile_File_009999'
  • for 10,000 to 99,999 'Outfile_File_010000' - 'Outfile_File_099999'
Apologies, I should have been a bit more precise. But I hope this clearifies things.
Thanks

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2020 年 7 月 27 日
編集済み: Image Analyst 2020 年 7 月 27 日
What I'd do is
name2 = sprintf('Output_File_%6.6d.tif', i);
  1 件のコメント
abhimanyu dubey
abhimanyu dubey 2020 年 7 月 27 日
Got it. Thanks a lot Sir. :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by