Vectorizing Code Yields Different Answer to For-Loop
1 view (last 30 days)
Show older comments
I ended up quickly writing a piece of code that theoretically should plot one value for each plot, giving 10 of them in total. It does do this. What if I wanted to remove the for-loop? I could vectorize the code simply by removing the for-loop, but then this plots a single plot with all the values upon it. Is there a way for me to remove the for-loop, but have my program plot a single value for each of the 10 iterations, yielding 10 plots as before?
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
3 Comments
Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!