MATLAB: Imwrite with variable filename

colormapimwrite

Hi,
I'm trying to call imwrite in a loop:
ori_dir = 'path/to/folder'
files = {'fi','le','na','me'};
for k = 1:length(files)
% do some operation on img %
write_dir = strcat(ori_dir, '/', files(k),'.tif');
imwrite(img, write_dir);
end
I'm getting the following error
Error using imwrite>parse_inputs (line 510)
A filename must be supplied.
Error in imwrite (line 418)
[data, map, filename, format, paramPairs] = parse_inputs(varargin{:});
write_dir contains a string to the correct path however. If I paste the string directly in imwrite, I don't have any issue, eg:
imwrite( img, 'path/to/folder/fi.tif')
does not raise an error.
I'm not quite sure what is wrong here. The variable files is a cell array with only strings in it.
Any help would be really appreciated!

Best Answer

Correct this line
write_dir = strcat(ori_dir, '/', files{k},'.tif')