如何编辑保存在.fig文件中的图形的属性而不显示它 [英] How to edit property of figure saved in .fig file without displaying it

查看:1327
本文介绍了如何编辑保存在.fig文件中的图形的属性而不显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编辑保存为.fig(MATLAB的默认格式)文件的MATLAB数字的某个属性。



我创建了很多图形密集的数字脚本,所以我选择不使用 set(0,'DefaultFigureVisible','off')隐藏默认图形来显示它们。这将任何新数字的'Visible'属性设置为'off'。这样,我可以创建,编辑,保存等数字,而不需要绘制它们,这可能会对CPU,GPU和它们的记忆产生影响。我使用 saveas(句柄,'filename.fig')命令将数字保存为.fig文件。这也保存了'Visible'属性,当我打开图形时(例如双击我的Windows资源管理器中的文件),这是一个问题。它会加载图形,但不显示它,因为它的'Visible'属性设置为'off'



我希望所有的.fig文件保存在上的'属性上。我没有显示(=征税)数字来达到这个目的?当我使用 set(handle,'Visible','on')时,绘制图形。

所以基本上,我想编辑的文件在一个较低的水平上,当它被加载为一个数字在MATLAB。



我认为这可以做到如下,但我不知道如何实现它。可以使用 s = load('filename.fig',' - mat'); 加载.fig的数据,就好像它是.mat文件一样。这会加载一个结构 s ,其中包含一些包含所有图形数据,属性等的字段。现在,图柄必须在这个未知的结构中找到,'Visible'属性和编辑的句柄一起使用



这样做可以不用绘制图形吗?



我尝试了,但没有成功,使用 fopen fread 和他们的朋友。



有人知道怎么做我想做的事吗? / DIV>

I类基础我从张贴由user4506754 URL中的线程上的解决方案: HTTP ://www.mathworks.com/matlabcentral/newsreader/view_thread/306249
目前,赫塞·霍普金斯职位(15后),您可以编辑属性 'ResizeFcn'在MATLAB创建图形时执行一个函数。这在我的MATLAB安装中不起作用,但引导我查看可以附加到其属性中的图形的不同功能。此页面记录所有图形属性: http://mathworks.com/help/matlab/ REF /数字-properties.html 。在那里我找到了'CreateFcn'属性。它的描述包含:

lockquote

这个属性指定了一个回调函数,当MATLAB创建图形时执行。 MATLAB在执行CreateFcn回调函数之前初始化所有图形属性值。

这意味着图形将被加载其属性,包括'Visible'属性是'off',然后是'CreateFcn'



设置'CreateFcn'使图形可见,然后解决我的问题。 b
$ b

  set(gcf,'CreateFcn','set(gcf,'')''''''''')

一个例子:

  ezplot(@sin)%绘制含有正弦波,标题等
组(GCF一个简单的数字, '可见', '关闭', 'CreateFcn', '设置(GCF,' '可见' ''''on'')'%这样会禁用图形并同时设置'CreateFcn'属性
saveas(gcf,'sin.fig')%将当前文件夹中的图像保存为.fig文件
close%关闭当前数字

否w转到资源管理器中的当前文件夹,然后双击sin.fig文件,它使MATLAB加载它,并绘制图形。



找到了解决方案。

这不会编辑.fig文件,正如我最初所问(作为一个解决方案),但它是一种替代解决方案原来的问题。现在,我可以创建和保存图形,而不会看到它们,但是在MATLAB加载的时候绘制这些图形。


I want to edit a certain property of MATLAB figures saved as .fig (MATLAB's default format) files.

I create a lot of graphics-intensive figures in a script, so I choose not to display them by making the default figure invisible with set(0,'DefaultFigureVisible','off'). This sets the 'Visible' property of any new figure to 'off'. This way I can create, edit, save, etc., figures without the need to draw them, which can be taxing on CPU, GPU and their memories. I save the figures as .fig files using the saveas(handle,'filename.fig') command. This also saves the 'Visible' property, which is a problem when I do want to open the figure (e.g. by double-clicking the file in my Windows Explorer). It loads the figure, but it doesn't display it because its 'Visible' property is set to 'off'.

I want all .fig files to be saved with the property set to 'on', but how can I achieve this without displaying (= taxing) the figures? The moment I use set(handle,'Visible','on'), the figure is drawn.

So basically, I want to edit the file on a lower level than when it's loaded as a figure in MATLAB.

I think it could be done as follows, but I do not know exactly how to achieve it. One can load the .fig's data as if it were a .mat file using s=load('filename.fig','-mat');. This loads a structure s containing some fields that contain all the figure's data, properties, etc. Now, the figure handle must be found in this unkown structure and the 'Visible' property that goes along with the handle edited.

Can this be done without the figure being drawn?

I tried, but haven't succeeded, using fopen, fread and their friends.

Does anybody know how to do what I want to do?

解决方案

I base my solution on the thread from the url posted by user4506754: http://www.mathworks.com/matlabcentral/newsreader/view_thread/306249 There, Jesse Hopkins posts (post 15) that you can edit a property 'ResizeFcn' to execute a function when MATLAB creates a figure. This doesn't work on my MATLAB installation, but lead me to look into the different functions you can attach to a figure in its properties. This page documents all figure properties: http://mathworks.com/help/matlab/ref/figure-properties.html. There I found the 'CreateFcn' property. Its description contains:

This property specifies a callback function to execute when MATLAB creates the figure. MATLAB initializes all figure property values before executing the CreateFcn callback.

It means that the figure is loaded with its properties, including the 'Visible' property being 'off' and then 'CreateFcn' is called.

Setting 'CreateFcn' to make the figure visible then solves my problem.

set(gcf,'CreateFcn','set(gcf,''Visible'',''on'')')

An example:

ezplot(@sin) % draw a simple figure containing a sine wave, title, etc.
set(gcf,'Visible','off','CreateFcn','set(gcf,''Visible'',''on'')' % this disables the figure and set the 'CreateFcn' property simultaneously
saveas(gcf,'sin.fig') % save the figure in the current folder as a .fig file
close % closes current figure

Now go to the current folder in your Explorer and double-click the sin.fig file. It makes MATLAB load it and, poof, the figure is drawn.

Solution found.

This doesn't edit the .fig file, as I originally asked (as a solution), but it is an alternative solution to the original problem. Now I can create and save figures without them being visible, but draw the figures the moment they're loaded by MATLAB.

这篇关于如何编辑保存在.fig文件中的图形的属性而不显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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