在 Matlab 中绘图

发布于 2024-08-31 07:35:28 字数 91 浏览 4 评论 0原文

Matlab中如何同时绘制两个图形?每次我使用 surf() 时,它都会在旧的上绘制。另外,如何保存图像以便将它们导出到 MS Word 或 Powerpoint 等?

How do you plot two figures at the same time in Matlab? Every time I use surf() it plots over the old one. Also, how do you save the images so you can export them to MS word or powerpoint or something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

勿忘初心 2024-09-07 07:35:28

您可以在单独的窗口中绘制两个图形:


figure(1)
% do plotting
figure(2)
% do plotting

或在子图中:


figure(1)
subplot(1, 2, 1)
% do plotting
subplot(1, 2, 2)
% do plotting

有关详细信息,您可以查看图形和子图函数的 MATLAB 文档(在帮助菜单中)。

要将图像打印到文件,请参阅打印功能的文档。或者直接转到文件 ->另存为,然后选择您想要的图像类型。

You can plot two figures in separate windows:


figure(1)
% do plotting
figure(2)
% do plotting

or in subplots:


figure(1)
subplot(1, 2, 1)
% do plotting
subplot(1, 2, 2)
% do plotting

For more info, you can see the MATLAB docs for the figure and subplot functions (in the help menu).

For printing the images to a file, see the documentation for the print function. Or just go to File -> Save As, and pick the image type you want.

亚希 2024-09-07 07:35:28

在每个绘图/冲浪/网格之前使用命令图形。

例子

X = [1:5];
figure('Name', 'My plot');
plot(X, X+X);
figure('Name', 'My plot number 2');
plot(X, X + X + X);

Use the command figure before each plot/surf/mesh.

example

X = [1:5];
figure('Name', 'My plot');
plot(X, X+X);
figure('Name', 'My plot number 2');
plot(X, X + X + X);
生活了然无味 2024-09-07 07:35:28

在调用 surf 之前调用 figurefigure 打开一个新的图形窗口。当您调用surf时,它将绘制到当前选定的图形中。

您可以使用图形窗口中的菜单“编辑”->“复制图形”将图形复制粘贴到 Word 或 Powerpoint 中。如果在 Word 中,单击粘贴的图形并选择“取消分组”,您甚至可以去编辑该图形。

要保存,请在图形窗口的文件菜单中选择“另存为...”。对于 Adob​​e Illustrator,另存为 .eps(比 .ai 效果更好)。

Call figure before calling surf. figure opens a new figure window. When you call surf, it will plot into the currently selected figure.

You can copy-paste figures into Word or Powerpoint by using, in the figure window, the menu Edit->Copy Figure. If in, say Word, you click on the pasted figure and select 'ungroup', you can even go and edit the figure.

To save, you select 'Save as...' in the File-menu in the figure window. For Adobe Illustrator, save as .eps (works better than .ai).

软糖 2024-09-07 07:35:28

作为对先前响应的另一个小补充,您可以使用 print -dmeta 命令将图形直接打印到剪贴板。然后只需粘贴到 Word 或 PowerPoint 文档即可。我发现它非常整洁。

As another small addition to previous responses, you can print a figure directly to clipboard using print -dmeta command. Then just paste to Word or PowerPoint document. I found it very neat.

ㄖ落Θ余辉 2024-09-07 07:35:28

@kwatford如果您使用hold all而不是hold on,那么Matlab将使用该图的下一个定义的颜色和线条样式。查看

figure(1);
plot(rand(100,1));
hold on ;
plot(rand(100,1)+2);

和之间的区别

figure(2);
plot(rand(100,1));
hold all;
plot(rand(100,1)+2);

@kwatford If you use hold all rather than hold on then Matlab will use the next defined colour and linestyle for that plot. check out the difference between

figure(1);
plot(rand(100,1));
hold on ;
plot(rand(100,1)+2);

and

figure(2);
plot(rand(100,1));
hold all;
plot(rand(100,1)+2);
油饼 2024-09-07 07:35:28

要在单独的窗口中创建新图形,只需说出figure。要导出为图像文件,请使用 print 命令和相应的 -d 选项来选择文件格式。就像这样:

figure;
plot(rand(100,1), rand(100, 1), 'r*');
print -dpng 'MyImage.png'

To create a new figure in a separate window, just say figure. To export as an image file, use the print command with the appropriate -d option to select the file format. Like so:

figure;
plot(rand(100,1), rand(100, 1), 'r*');
print -dpng 'MyImage.png'
内心荒芜 2024-09-07 07:35:28

执行 hold on 以保持当前图形。新的地块将被添加到现有的地块中。使用 hold off 将其改回之前的行为。

除了print命令(参见Drew Hall的回复)之外,您还可以通过“文件”菜单导出为其他格式,或使用编辑菜单的“复制图形”功能。如果您想将其粘贴到Word或Powerpoint中,使用“选择性粘贴”而不是普通粘贴可能会得到更好的结果。

Execute hold on to hold the current figure. New plots will be added to the existing plots. Use hold off to change it back to the previous behavior.

In addition to the print command (see Drew Hall's response), you can export to other formats via the File menu, or use the Copy Figure function of the edit menu. If you want to paste it into Word or Powerpoint, you might get a better result if you use "Paste Special" instead of normal Paste.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文