rename file extension from 1.png to 001.png and so on

4 ビュー (過去 30 日間)
Tulips
Tulips 2012 年 10 月 12 日
hi everyone,can I know how to rename the extension of 1.png to 001.png in matlab script!for your information, from the loop of my coding, the file has been created as 1.png and saved in a folder. however, I want to name the file as 001.png in my matlab script. how to do it.besides, if I have more than one file I should make it automatically rename as 001.png, 002.png ,003.png. how to make it? thank you.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 12 日
編集済み: Azzi Abdelmalek 2012 年 10 月 12 日
folder='D:\answers\'
for k=1:1
file1=sprintf('%d.png ',k)
file2=sprintf('00%d.png',k)
dos_com=['!rename ', folder file1 file2]
eval(dos_com)
end
Edited code (Simon's suggestions)
folder='D:\answers\' % e.g
for k=1:4
file1=[folder sprintf('%d.png ',k)]
file2=[folder sprintf('00%d.png',k)]
movefile(file1 ,file2]
end
  23 件のコメント
Walter Roberson
Walter Roberson 2012 年 10 月 15 日
Have you moved the existence test to before you imwrite() ? Are you doing something meaningful when you find that the file exists?
And are you truly wanting to output exactly the same output file for BlobsNo's worth of files ? Notice that once you have converted the image to grayscale when k=1, and resized to 40 x 40, that subImage will remain grayscale and 40 x 40 for all the rest of the values of k.
Tulips
Tulips 2012 年 10 月 15 日
the save filed should be not overwritten when I tried run with other image.this is the proble. pls help.i am not really good in build matlab syntax

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 10 月 12 日
編集済み: Walter Roberson 2012 年 10 月 12 日
  1 件のコメント
Image Analyst
Image Analyst 2012 年 10 月 12 日
As will the traditional C-like way:
baseFileName = sprintf('%3.3d.png', FileNumber);

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

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by