避免使用plot / step / ...输出

时间:2012-10-28 16:50:22

标签: matlab

是否有任何函数可以避免m文件的绘图输出?

我的意思是我在文件的开头放置一个函数(如clc),然后阻止所有的绘图函数。

4 个答案:

答案 0 :(得分:1)

我不知道有一个命令可以做到这一点,但你可以用一小段额外的代码来完成。

% Declare a variable for skipping at the top of your .m file
skip = 1; %example, 1 = skip, 0 = plot

% do things....

% Then nest your plot commands
if (skip == 0) % wants to plot in this case
  % Whatever plot code in here
  plot(x,y);
end

这应该可以解决问题,但我发现它并不像你要求的那样干净,单一的功能。我希望它有所帮助! :)

此外,我了解如果您不一定使用自己的.m文件,或者脚本很长,这可能不实用。

答案 1 :(得分:1)

您可以使用自己的内置绘图函数重载(嵌套在函数内或同一目录中):

function myfun(a,b)
    plotting = false;
    plot(a,b);
    plot(b,a);

    function varargout = plot(varargin)
        if plotting
            [varargout{1:nargout}] = builtin('plot',varargin{:});
        end
    end
end

当您致电myfun时,不会发生任何事情,除非您当然更改plotting=false

有关重载内置函数的额外信息:http://www.mathworks.nl/support/solutions/en/data/1-18T0R/index.html?product=ML&solution=1-18T0R

答案 2 :(得分:1)

您可以使用

使所有 matlab图不可见
set(0, 'DefaultFigureVisible', 'off');

off更改为on可以撤消此过程(您可能需要执行此操作,因为这会关闭所有您的图表!)

您可以将该行添加到m文件的开头,然后添加

close all;
set(0, 'DefaultFigureVisible', 'on');
到最后。

答案 3 :(得分:0)

您也可以在绘图之后编写close all,然后绘制它们,但在之后立即关闭。它不干净但有效。

相关问题