整个循环完成后,在循环中绘制并保存绘图
我需要不断更新循环内的绘图,因为我正在对空间中的每个部分进行线性回归。我可以很好地做到这一点并显示正确的情节。但我似乎无法将最终的绘图保存到文件中。我的代码看起来像:
for i = 1:slabs
%.....SOME LOOPED RESULTS HERE, SHORTENED FOR BREVITY.....
p = polyfit(collectCoord, collectTemp, 1);
t2 = floor(min(collectCoord)) : 0.1 : ceil(max(collectCoord));
y2 = polyval(p,t2);
h = plot(collectCoord, collectTemp, 'o', t2, y2);
xlabel('X-Coordinate')
ylabel('Temperature')
axis([-8 8 50 800])
hold on
end
filename = [folder 'Plot' num2str(stepCount) '.jpg'];
saveas(h, filename);
我在这里到底做错了什么,或者有更好的方法来保存情节吗?
I need to keep updating a plot within a loop because I am doing a linear regression for each segment in space. I can do that just fine and display a correct plot. But however I don't seem to be able to save the final plot to file. My code looks something like:
for i = 1:slabs
%.....SOME LOOPED RESULTS HERE, SHORTENED FOR BREVITY.....
p = polyfit(collectCoord, collectTemp, 1);
t2 = floor(min(collectCoord)) : 0.1 : ceil(max(collectCoord));
y2 = polyval(p,t2);
h = plot(collectCoord, collectTemp, 'o', t2, y2);
xlabel('X-Coordinate')
ylabel('Temperature')
axis([-8 8 50 800])
hold on
end
filename = [folder 'Plot' num2str(stepCount) '.jpg'];
saveas(h, filename);
What exactly is it that I am doing wrong here, or is there a much better way of saving the plot?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在刚刚绘制的线的句柄上调用 saveas() 。您需要提供一个图形句柄:
You're calling saveas() on the handle to the line you just plotted. You need to supply a figure handle: