Ok, I have an issue that seems quite strange to me, and I don't exactly understand why I am getting mixed results when I run the same code. I wrote a test code sample below to illustrate the problem I am having.
cd('~/Documents/MATLAB/plots/test')
for x = 1:1:10;
y = x+2;
plot(x,y,'*')
filename = strcat('x_',num2str(x));
print(gcf,'-painters','-dpdf',strcat(filename,'.pdf'));
end
This code literally takes x = 1, 2, ... and adds a value of 2 to it. I wrote this test program to see if indeed I could make 10 figures that automatically save as PDF files, dynamically assigning the filename, with each plot graphing a single point. This works exactly as intended except for one major issue - the PDF files are corrupted. Running the same code without modifications sometimes gives the first 3 plots correctly saved, and able to be viewed, with the rest corrupted. Other times, all 10 are corrupted. Does anyone have a clue as to why I would obtain such results?
Furthermore, when I use code, the filename being modified to include more variables, in my actual program, I obtain the following error:
Error using ghostscript (line 186)
Problem converting PostScript. System returned error: -1.Failed to convert to output format; Ghostscript status: -100.Error: /ioerror in
--.outputpage--
Does anyone have any suggestions on how I might attack this issue? Furthermore, I know I can vectorize code to forgo for-loops. If I wanted to graph the entire line y = x+2 from [1,10], then using x = 1:1:10 is the obvious way to vectorize the code. In the above, I used a for-loop to separate out the graphs so that each graph contains one point. Vectorizing it via x = 1:1:10 would graph the whole line at once, which is what I don't want. Is there a way to do what my code does above without a for-loop?