Saving Plots to a Folder with the Title Name

I'm trying to plot a series of plots in a loop with the following data:
x1 = [ 1 2 3 4 5]
y1 = [ 1 1 1 1 1]
x2 = [ 1 2 3 4 5]
y2 = [ 2 2 2 2 2]
x3 = [ 1 2 3 4 5]
y3 = [ 2 2 2 2 2]
plot(x,y)
title('First Plot')
THEN suppress the output and save all plots to a folder,
with the each file displaying the title names:
First Plot
Second Plot
Third Plot
Thanks,
Amanda

4 commentaires

Matt Kindig
Matt Kindig le 16 Mai 2013
Sounds straightforward enough. What are you having difficulty with? Please post the code that you've done so far.
Amanda
Amanda le 16 Mai 2013
I have the looping part. I'm having trouble saving the title names as displayed on the plot to the filenames in the folder.
Matt Kindig
Matt Kindig le 16 Mai 2013
Can you still post your code?
Amanda
Amanda le 16 Mai 2013
Modifié(e) : Amanda le 16 Mai 2013
Thanks David, This will work.

Connectez-vous pour commenter.

 Réponse acceptée

name = 'my_name';
for k = 1:3
name_2 = strcat(name,num2str(k));
h=figure;
plot(x(k),y(k)); % your data there
my_title = strcat('title_',num2str(k));
title(my_title)
saveas(h,name,'jpg')
end
If you do not need to see the plot, you can hide it:
h=figure('visible','off')

1 commentaire

Amanda
Amanda le 16 Mai 2013
That is it. Some reason the title name was giving me trouble.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur App Building dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by