I am writing a program to plot graphs in a loop and I want to save each graph that comes out as a .jpg file with a variation of the file name. Here is my code for saving the graphs:
filename = strcat('WI_Pollutants_', D(i,6), '_200706_O3');
saveas(gcf, filename, 'jpg');
The saved file should come out as the following with D(i,6) changing each iteration of the loop.
WI_Pollutants_003-0010_200706_O3.jpg
However, I'm running an error: (Maybe it has to due with saveas
wanting a string only?)
Error using saveas (line 81)
Invalid filename.
D(i,6)
is prior to this loop? And for that matter, filename? – PearsonArtPhotoD
is the sorted cell matrix of the O3 data. So it's all the data forO3_sorted
. i goes from 1 to 32 and is the 32 unique county-site codes (sites where O3 is measure). Therefore,D(i,6)
is the 6th column ofO3_sorted
, pulling out only the rows where the county-site code is the same as whatever is in i at the time (such as '003-0010' for i = 1).filename
is what I want to name the graph that comes out. For example,WI_Pollutants_003-0010_200706_O3.jpg
.filename
creates this name, changing the003-0010
part for each new graph. – SugaKookie