问题描述
保存图形时,Matlab使用什么功能?例如,当用户选择文件>另存为...然后选择.png或其他图像格式时,幕后发生了什么?
When saving a figure, what function does Matlab use? For example, when a user selects File > Save As... and then selects .png or another image format, what is going on behind the scenes?
我问,因为我正在尝试自动保存,但当我使用 saveas
或 print ,生成的图像实际上是像素化的。但是,当我使用上述方法保存图形时,图像看起来非常好。
I am asking because I am trying to automate saving, but when I use saveas
or print
, the resulting image is really pixelated. However, the image looks really good when I save the figure using the method described above.
我应该使用什么方法从命令行保存图形?图窗口使用的实际方法可以使用,但是如果你们有更好的解决方案,我会对它进行评估!
What method should I use to save my figure from the command line? The actual method that the figure window uses would work, but if you guys have better solutions, I'd appricate it!
推荐答案
另存为...菜单项的回调调用函数FILEMENUFCN,第一个输入参数是菜单所在图形的句柄,第二个输入参数是字符串'FileSaveAs'
。如果您将数字句柄存储在变量 hFigure
中,则以下命令应相当于单击该图窗口中的另存为...菜单项: / p>
The callback for the "Save As..." menu item invokes the function FILEMENUFCN with the first input argument being the handle of the figure the menu is in and the second input argument being the string 'FileSaveAs'
. If you have the figure handle stored in the variable hFigure
, then the following command should be equivalent to clicking the "Save As..." menu item in that figure window:
>> filemenufcn(hFigure,'FileSaveAs');
一些注释......
-
函数FILEMENUFCN仅记录部分。您可以在命令窗口中执行
help filemenufcn
,但在线文档中没有条目。在MATLAB 2009a中,该函数可以在以下文件夹中找到:
The function FILEMENUFCN is only partially documented. You can do
help filemenufcn
in the command window, but there is no entry for it in the online documentation. In MATLAB 2009a, the function can be found in the following folder:
C:\Program Files\MATLAB\R2009a\toolbox\matlab\uitools\filemenufcn.m
查看功能代码,似乎它最终调用.fig文件的函数或函数(带有其他输入参数)用于其他文件类型。
Looking through the function code, it appears that it ultimately calls either the function SAVEAS for .fig files or the function HGEXPORT (with additional input arguments) for other file types.
通过搜索图窗口及其菜单的子项,我能够搜索另存为...菜单项的回调。您可以通过设置到'on'
然后遍历 href =http://www.mathworks.com/help/techdoc/ref/get.html =noreferrer> GET 命令。另一种方法是使用命令,假设您知道某些属性你正在寻找的对象。例如,这将找到当前图形窗口的文件菜单的句柄:
I was able to hunt down the callback for the "Save As..." menu item by searching through the children of the figure window and its menus. You can do this yourself by setting the root property 'ShowHiddenHandles'
to 'on'
and then traversing through the 'Children'
properties of the figure window and its menus using the GET command. An alternative is to use the FINDALL command, assuming you know some properties of the objects you are looking for. For example, this will find the handle to the "File" menu for the current figure window:
>> hFileMenu = findall(gcf,'Label','&File');
这将找到另存为...菜单项的句柄并显示其回调:
And this will find the handle to the "Save As..." menu item and display its callback:
>> hSaveAs = findall(hFileMenu,'Label','Save &As...');
>> get(hSaveAs,'Callback')
ans =
filemenufcn(gcbf,'FileSaveAs')
这篇关于在matlab中,如何将图形保存为图像,方法与使用“另存为...”相同。在图窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!