MATLAB Answers

Amanda
0

Save Figures to One Folder

Asked by Amanda
on 23 Apr 2013
Latest activity Edited by venkata reddy kopparthi on 12 Jul 2018
I want to save multiple figures to the same folder, with the name of figure_1, figure_2, etc.
Here is the code: x = 1:5;
y = [1,1,1,1,1]
z = [2,2,2,2,2]
a = [3,3,3,3,3]
b = [4,4,4,4,4]
c = [5,5,5,5,5]
figure;
plot(x,y)
figure;
plot(x,z)
figure;
plot(x,a)
figure;
plot(x,b)
figure;
plot(x,c)

  0 Comments

Sign in to comment.

2 Answers

Azzi Abdelmalek
Answer by Azzi Abdelmalek
on 23 Apr 2013
 Accepted Answer

figure;
h(1)=plot(x,y)
figure;
h(2)=plot(x,z)
figure;
h(3)=plot(x,a)
figure;
h(4)=plot(x,b)
figure;
h(5)=plot(x,c)
for k=1:5
saveas(h(k),sprintf('figure_%d.jpg',k))
end

  3 Comments

Image Analyst
on 24 Apr 2013
The above code saves to the current folder. To save it to a specific folder, use fullfile, as shown below:
baseFileName = sprintf('figure_%d.jpg',k);
% Specify some particular, specific folder:
fullFileName = fullfile('D:\myPlots', baseFileName);
figure(k); % Activate the figure again.
export_fig(fullFileName); % Using export_fig instead of saveas.
Undefined function or variable 'export_fig'. Matlab 2016

Sign in to comment.


Answer by venkata reddy kopparthi on 12 Jul 2018
Edited by venkata reddy kopparthi on 12 Jul 2018

  • we can save current open figure by saveas library
  • saveas(gcf,'<path>\figure_name.jpg');

  0 Comments

Sign in to comment.