MATLAB: Looking for an efficient way to activate all fprintf in the function

fprintf

I have a function and into it there are a lot of fprintf that print out some informations.I would create a way to show or not show this informations using only one flag.
for example
debug = 0;
if debug ~= 0
fprintf(...);
end
Since I have too many fprintf in the function I don't want write if every time but I would activate and deactivate fprintf once time for all printf

Best Answer

If you are using a function, you can overload fprintf with a nested function.
function myfunction(debug)
fprintf('first one\n');
fprintf('second one\n');
function fprintf(varargin)
if ~debug
builtin('fprintf', varargin{:});
end
end
end
you can then call with myfunction(true) or myfunction(false)