Hello,
I have couple of question on saving plots while a for-loop is continuously running. My code is:
interval=[0.01 0.1 0.5 1];
for i=1:length(x)
t=(0:interval(i):2*pi);
y = sin(t);
plot(t, y);
end
This code however shows the "Index exceeds the number of array elements (4)" error. I am not sure what is heppening here.
2) The second question is that I would like to save the output image file to a directory on my local folder as the fo-loop runs. The following code was used (for the same example above):
iinterval=[0.01 0.1 0.5 1];
for i=1:length(interval)
t=(0:interval(i):2*pi);
y = sin(t);
fig=figure(i);
plot(t, y);
basedir='C:\Users\Desktop\';
cd (basedir);
saveas(gca,fullfile(basedir,i),'.jpeg')
cd('C:\Users\');
end
The error shows: Unsupported format or extension: .jpg.
Basically I just need to see how the sine graphs vary with the size of the interval. Instead of manually doing things, I would love to have the plots saved to my destination as the for-loop runs but somehow I am running into more errors.
Thanks,
Mahith M
end