フィルターのクリア

How to name my files differently in a loop

1 回表示 (過去 30 日間)
Asser Abdelgawad
Asser Abdelgawad 2022 年 6 月 7 日
コメント済み: Image Analyst 2022 年 6 月 7 日
I want each "pic" to have a differnet name corresponding to n. i.e: 1.jpg, 2.jpg, etc.
This gives me an error because the n is not in quotations for a filename, but if I do this, then the images keep overwriting each other so that at the end I only have one image that is called "n". How do I avoid this?
for n = 1:68
pic(:,:,n) = Amp((n-1)*64+1:n*64,:);
pic(:,:,n) = wdenoise(pic(:,:,n));
pic(:,:,n) = uint8(pic(:,:,n));
imwrite(pic(:,:,n), colormap(), n,'jpg');
end

採用された回答

Image Analyst
Image Analyst 2022 年 6 月 7 日
編集済み: Image Analyst 2022 年 6 月 7 日
Try this
for n = 1:68
pic(:,:,n) = Amp((n-1)*64+1:n*64,:);
pic(:,:,n) = wdenoise(pic(:,:,n));
pic(:,:,n) = uint8(pic(:,:,n));
baseFileName = sprintf('%2.2d.png', n);
fullFileName = fullfile(pwd, baseFileName);
fprintf('Writing %d of 68 : "%s."\n', n, fullFileName);
imwrite(pic(:,:,n), fullFileName);
end
  2 件のコメント
Asser Abdelgawad
Asser Abdelgawad 2022 年 6 月 7 日
Thank you! Also, is there a way to change where the files are saved? imwrite automatically saves them to the same folder my .m file is in but I would like to save it elsewhere.
Image Analyst
Image Analyst 2022 年 6 月 7 日
Just assign some folder where you'd like to save them
folder = 'c:\whatever'
if ~isfolder(folder);
mkdir(folder);
end
for n = 1:68
pic(:,:,n) = Amp((n-1)*64+1:n*64,:);
pic(:,:,n) = wdenoise(pic(:,:,n));
pic(:,:,n) = uint8(pic(:,:,n));
baseFileName = sprintf('%2.2d.png', n);
fullFileName = fullfile(folder, baseFileName);
fprintf('Writing %d of 68 : "%s."\n', n, fullFileName);
imwrite(pic(:,:,n), fullFileName);
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by