Matlab openfig to existing figure

自作多情 提交于 2019-12-24 16:54:30

问题


When in Matlab I use openfig(filename); to open a saved figure, it always opens a new window. All the 'reuse' argument does is not load the file when it appears to already be open. However, I wish to open the file into a given figure, and just overwrite its contents. Is there a way to pass a figure handle to openfig, or is there another function that would accomplish this?

So in code, what I would like to do is something along the following lines:

f = figure;
openfig(filename, 'Figure',f);

and then the figure would be displayed in figure f rather than having opened a second figure window.


回答1:


I think you can arrange something close to what you want with the copyobj function. Here is a try with a docked figure:

% --- Create sample figure
h = figure;
ezplot('sin(x)');
set(gcf, 'Windowstyle', 'docked');

pause

% --- Replace the axes
clf
g = openfig('test.fig', 'invisible');
copyobj(get(g, 'CurrentAxes'), h);
delete(g);

Which gives me a smooth replacement of the axes, without flickering of the figure.

However, I don't know how this would behave with a fullscreen figure, it surely depends on the method you choose. Check also the doc of copyobj in detail, it's not copying everything so you may want to use the legacy option.



来源:https://stackoverflow.com/questions/28921113/matlab-openfig-to-existing-figure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!