MATLAB: How to save filenames


Hello friends,
I want to save files with dynamic name so I wrote the code:
for n=1:Ne
[r,c] = find(L==n);
imwrite(~n1, n, 'png');
But the file is not saved, is there any mistake in the code? Please guide.

Best Answer

  • 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.
  • Related Question