How to save filenames

2 views (last 30 days)
Sayed
Sayed on 2 Nov 2013
Answered: Image Analyst on 2 Nov 2013
Hello friends,
I want to save files with dynamic name so I wrote the code:
for n=1:Ne
[r,c] = find(L==n);
n1=imagen(min(r):max(r),min(c):max(c));
imshow(~n1);
imwrite(~n1, n, 'png');
But the file is not saved, is there any mistake in the code? Please guide.

Accepted Answer

Image Analyst
Image Analyst on 2 Nov 2013
Your problem is you didn't look in the help to see what the proper arguments are for imwrite
imwrite(~n1, n, 'png');
is not correct. You need to come up with a filename, such as
baseFileName = sprintf('%d.png', n);
fullFileName = fullfile(yourFolder, baseFileName); % yourFolder can be pwd if you want.
imwrite(n1, fullFileName);
The format argument 'png' is not needed because it determines the format from the filename.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 2 Nov 2013
Edited: Azzi Abdelmalek on 2 Nov 2013
imwrite(~n1, n, 'png');
Will not save any file, n is not a valid file name.
What does ~n1 represent?
  2 Comments
Sayed
Sayed on 2 Nov 2013
It is simple image data
Azzi Abdelmalek
Azzi Abdelmalek on 2 Nov 2013
Ok, what about your file name?

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!