How can i save the number of images stored in a cell array to my folder ?

2 ビュー (過去 30 日間)
shikha mangal
shikha mangal 2016 年 4 月 26 日
コメント済み: Jan 2016 年 4 月 26 日
How can i save all the images stored in a cell array in the matlab directory path,so that i can use them further.What is the syntax of writing multiple images from cell array to the system in jpg format?please help.
for i = 1:numel(myCellArr)
fileName = sprintf('image_%04d.jpg');
imwrite( myCellArr{i}, 'fileName.jpg' );
end
I have used this code but it is not saving all of my images stored in cell but only the last image.'please help me to obtain the desired result.

回答 (1 件)

Jan
Jan 2016 年 4 月 26 日
編集済み: Jan 2016 年 4 月 26 日
Almost correct:
for i = 1:numel(myCellArr)
fileName = sprintf('image_%04d.jpg', i); % "i" required
imwrite( myCellArr{i}, fileName);
end
In your code, you saved the files with the name 'fileName.jpg', but you want tzhe variable called "fileName".
A hint: Do not rely the current directory to be fixed. A graphics or timer callback can change the directory. Better use absolute file names:
folder = 'C:\Temp'; % Or whatever
for i = 1:numel(myCellArr)
fileName = fullfile(folder, sprintf('image_%04d.jpg', i));
imwrite( myCellArr{i}, fileName);
end
  2 件のコメント
shikha mangal
shikha mangal 2016 年 4 月 26 日
Thanks Jan Simon.It helped me in saving images.Thanks once again.
Jan
Jan 2016 年 4 月 26 日
You are welcome.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by