MATLAB: Writing a sequence of images inside a for loop using matix

jishnu

i have sequence of images formed by processing inside a for loop. I need to write them into a new folder using the concept of matrix

Best Answer

Jishnu - since your code produces a new image at each iteration of the for loop, then you could do something like the following
% initialize the folder/path
folderToSaveImg = '/Users/myName/someDirectory/images';
% do your loop
for k=1:100
% do the processing to create the image named img
img = randi(255,100,100,3); % example only
% create the file name
fileName = sprintf('image%d.mat',k);
% join the file name to the folder name
fileDestination = fullfile(folderToSaveImg, fileName);
% save the image as a matrix
save(fileDestination,'img');
end
The above code (example only) will save 100 images from the sequence to individual mat files where the data stored in the file is a three dimensional matrix.