是否有任何功能可以避免 m 文件的绘图输出?
我的意思是我在文件的开头放置了一个函数(如 clc),然后所有绘图函数都被阻止。
您可以使用自己的(嵌套在您的函数内或同一目录中)重载内置绘图函数:
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
您可以使用以下命令使所有matlab 绘图不可见:
set(0, 'DefaultFigureVisible', 'off');
更改off
为on
反转该过程(您可能需要这样做,因为这将关闭您的所有情节!)
您可以将该行添加到您的 m 文件的开头,然后添加
close all;
set(0, 'DefaultFigureVisible', 'on');
到最后。
我不知道执行此操作的单个命令,但是您可以使用一点额外的代码来完成。
% 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 文件,或者脚本很长,这可能不切实际。
您也可以close all
在情节之后写,它们将被绘制但在之后瞬间关闭。它不干净但有效。