How to save all opened window Figure (imshow) with specified name and folder?
Show older comments
I already use the code that I found from MathWorks forum. I wanna save all opened figure (imshow) into spesified folder and name. I have no found error but its result isn't that I want it. The result saves the 7 different name which I want to do but all of them are the last figure, meanwhile I wanna each figure with each name. For an example: Figure 1 is stored with name => resultImage_1.jpg
Figure 2 is stored with name => resultImage_2.jpg
% Specify the folder where the files live.
myFolder = 'D:\DIAH\[MATLAB]cv1-fingerspelling-recognition-master\cv1-fingerspelling-recognition-master\imagessss';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
currentImageArray = imread(fullFileName);
currentImage{k}=currentImageArray;
for i = 1 : 7
outputFolder = 'D:\DIAH\[MATLAB]cv1-fingerspelling-recognition-master\cv1-fingerspelling-recognition-master\Hasil Percobaan Lab';
outputFileName = fullfile(outputFolder, ['Hasil Citra Lab_' num2str(i) '.jpg']);
imwrite(currentImage{k}, outputFileName);
% drawnow; % Force display to update immediately.
end
end
Accepted Answer
More Answers (1)
Jon
on 12 Jul 2019
1 vote
The problem is that in your inner loop you set i = 1,2,3...7 but you are writing currentImage{k}. So the index for k does not change, you just write the same file, currentImage{k}, 7 times. It isn't clear to me what the purpose is of this inner loop on index i. Maybe it is not needed. In anycase, you need to look at your loop structures, and make sure that the indices that are being changed are connected to the files you want to write.
Categories
Find more on Environment and Settings 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!