在MATLAB中绘图并另存为文件 [英] Plotting and Saving as File in MATLAB

查看:101
本文介绍了在MATLAB中绘图并另存为文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在MATLAB中绘制并保存到图像文件.这是我在"for"循环中调用的代码:

I need to plot and save to image file in MATLAB. Here is the code that I am calling inside a 'for' loop:

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 ,但我相信我需要为它们使用手柄.有人可以帮我吗?

Now, this is starter code that I am using for some work and I don't understand it completely (example - the command 'figure'). There have been suggestions to use saveas or print but I believe I need handles for them. Could someone help me out here?

谢谢.

推荐答案

figure()是一个返回图形句柄的函数:

figure() is a function which returns a handle to the figure:

f = figure()
scatter(data_x_pos,data_y_pos,'r*')
...

然后您可以使用此手柄保存图形:

You can then use this handle to save the figure:

saveas(f, 'image.png');

看看有关处理图形的教程,以了解更多信息.

Take a look at the tutorials on Handle Graphics to learn more.

scatterplot还将句柄返回到它们绘制的点,线或其他集合.

scatter, and plot also return handles to the collection of points, or the lines, or whatever, they've plotted.

这篇关于在MATLAB中绘图并另存为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆