50

有没有办法告诉 Matlab不要在图形命令(如figureplot. 这将大大提高我的工作效率,因为我经常希望在数据(重新)处理期间继续进行代码开发。

4

2 回答 2

43

It is possible, the trick is to not use the figure statement, but to change the current figure directly. This will change the active plot without changing the focus. Typically I do something like this:

function change_current_figure(h)
set(0,'CurrentFigure',h)

Then, all of the figure(h) statements need to be changed to change_curent_figure(h).

Note, this is included in the matlab documentation.

It should be noted, this only works if the figure is already created. If new figures are going to be periodically created, one could create the figures as the very first few lines of code, save the handles, do the processing, and then plot to them. This example would work. Note, the drawnow command will flush the event buffer, making sure all figures are plotted.

I've seen this work from 2007-2010, not sure if the latest or earlier versions support this, although I have no reason to suspect they don't.

fig1=figure;
fig2=figure;
drawnow;
[a b]=do_complex_processing;
change_current_figure(fig1)
plot(a);
change_current_figure(fig2)
plot(b);
于 2011-12-13T13:13:04.337 回答
4

我也有同样的问题,代码创建数字来自外部供应商的额外复杂性,我不想修改它。以下是在 Matlab 2014b 上测试的两种可能性(在 MathWorks 支持的帮助下确定):

1.生成图形不显示,代码完成后显示

set(0, 'DefaultFigureVisible', 'off');

for i = 1:10
    fprintf('i: %g\n', i)
    figure;
    pause(1);
end

set(0, 'DefaultFigureVisible', 'on');
figHandles = findall(0, 'Type', 'figure');
set(figHandles(:), 'visible', 'on')

这段代码完全符合需要,但增加的不便是您看不到代码运行的任何进度,因此如果出现问题,则无法中断长时间的运行。

2.停靠数字

  1. 创建一个新图形:

    figure
    
  2. 停靠它:

    在此处输入图像描述

    这会将图形放入 Matlab IDE 窗口。

  3. 使新数字停靠并运行代码:

    set(0, 'DefaultFigureWindowStyle', 'docked');
    
    for i = 1:10
        fprintf('i: %g\n', i)
        figure;
        pause(1);
    end
    
    set(0, 'DefaultFigureWindowStyle', 'normal');
    
于 2016-02-25T16:48:04.860 回答