我从您的 cmets 中假设您的意思是您有很多调用 waitbar 的函数。
您可以使用自己的waitbar.m 重载“waitbar”函数,确保它在搜索路径上的位置更高。虽然这通常不是一个好主意,并且将来当您(或您使用您的代码的任何其他人)确实想要使用等待栏但它没有出现时可能会导致问题。
另一种(在我看来更可取的)禁用它的方法是创建您自己的中间函数,您可以在其中打开/关闭等待栏:
function h = mywaitbar ( varargin )
% preallocate output
h = [];
% use an internal persistent variable
persistent active
% by default set to true
if isempty ( active ); active = true; end
% Check to see if its a control call
if nargin == 1 && ischar ( varargin{1} )
% is it a call to disable it?
if strcmp ( varargin{1}, '**disable**' )
active = false;
else
active = true;
end
return
end
if active
h = waitbar ( varargin{:} );
end
end
这样做的缺点是您需要使用新功能“waitbar”查找并替换所有等待栏命令,但这是一次性操作。
然后通过以下方式禁用所有未来对 waitbar 的调用:
mywaitbar ( '**disable**' )
运行您的代码,不会显示等待栏。使用永久变量将保持状态,直到您重新启动 Matlab(或您调用 clear all)。要停止“全部清除”重置它,您可以在函数中使用mlock。
要重新启用等待栏:
mywaitbar ( '**enable**' )
使用以下代码对其进行测试:
for ii=1:10
h = mywaitbar ( ii );
fprintf ( 'test with waitbar %i\n', ii);
end
现在禁用等待栏功能:
mywaitbar ( '**disable**' )
for ii=1:10
h = mywaitbar ( ii );
fprintf ( 'test with waitbar disabled %i\n', ii);
end
您会看到上面的代码运行时没有显示等待栏。