Reputation: 23
I have an array in the form of
a = {'a','b',...'t'};
b = {'1','2',....'20'};
I'm doing stuff to plot my data sets (I have 20 of them) via loop, and I want to save my figures like so:
a1.jpg
b2.jpg
.
.
.
for all 20 data sets.
So, my configuration is in the form of
for i = 1:10
*do stuff to get plot*
save(....)???
I don't know how to do this. I have a h=figure; term, and I was expecting to do something along the lines of
save(h,'dataset_a(i)_b(i),'jpg')
However, the naming has to exploit the entries of my 'a' and 'b' array. How could I formally add string entries like so from arrays?
Upvotes: 1
Views: 51
Reputation: 1894
You must create a string for filename to save:
for i = 1:10
h = plot(); % anything to plot here
fname = strcat('dataset_', a{i}, '_', b{i});
saveas(h, fname, 'jpg');
end
Note that you have to use saveas
instead of save
. Using save
cannot give you output format JPEG even if you used .jpg
in the file name (it creates a .jpg
file but cannot be opened).
Upvotes: 2