我需要在 MATLAB 中绘图并保存到图像文件。这是我在“for”循环中调用的代码:
figure
scatter(data_x_pos,data_y_pos,'r*')
hold on
scatter(data_x_neg,data_y_neg,'b')
t = linspace(-80,80);
y = -model.w(1)*t/model.w(2);
plot(t,y,'k');
% need to save this plot to image to a file here
现在,这是我用于某些工作的起始代码,但我并不完全理解它(例如 - 命令“figure”)。有人建议使用 saveas 或 print 但我相信我需要它们的句柄。有人可以帮我吗?
谢谢。
最佳答案
figure()
是一个返回图形句柄的函数:
f = figure()
scatter(data_x_pos,data_y_pos,'r*')
...
然后您可以使用此句柄来保存图形:
saveas(f, 'image.png');
看看 tutorials on Handle Graphics了解更多。
scatter
和 plot
也返回点、线或其他它们绘制的集合的句柄。
关于matlab - 在 MATLAB 中绘图并保存为文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7617843/