Chris - imwrite does not return a parameter, so the too many output parameters makes sense. Replace your line convertToTif = imwrite(imageData, 'tif');
with just
imwrite(imageData, 'myNewFileName','tif');
and it should work fine so long as you pass in a file name for this image. In the above, replace the string 'myNewFileName' with a string of your choosing, or use the filename from pgmFileName as
[~, tifFileName, ~] = fileparts(pgmFileName);
imwrite(imageData, tifFileName,'tif');
As for passing in an array of files to be saved individually, I don't think that is possible. You could use perhaps use cellfun if you had a cell array of the filenames, but I think what you have above should work fine once you make some corrections.
Best Answer