Re: semi-colon suppress output of user defined function





"Andy " <myfakeemailaddress@xxxxxxxxx> wrote in message news:iqjg3l$570$1@xxxxxxxxxxxxxxxxxxxxxxxxxxx
The problem you're having is that the semicolon suppresses OUTPUT (that is, will not display the RETURNED values). 'Output' does not refer to all data printed to the command line during execution.

It sounds like you're implementing a 'verbose' option to your function, and this should be done via an optional argument, not the semicolon supression.

function MyFun(...,verbose)
%...
for ix = 1:1e5
if verbose
printf('Currently executing loop %d', ix);
end
% do whatever in the loop
end
end

As a matter of good program design, your functions probably should never print directly to the screen. If you want them to, the caller should pass the 'verbose' option, and every print statement should be wrapped in:

if verbose
print(...)
end

Or even better, you shouldn't just DISP/FPRINTF/etc. you should call a logging function:

for ix = 1:1e5
logDiagnostics(verbose, ...)
end

and let the logging function determine what information to write and to where it should be written (screen if verbose is 'display', a log file if verbose is 'logging', etc.) To add a new log destination or logging "level" in the future all you need to do is modify the one logDiagnostics function rather than dozens or hundreds of uses of "if verbose".

--
Steve Lord
slord@xxxxxxxxxxxxx
To contact Technical Support use the Contact Us link on http://www.mathworks.com

.



Relevant Pages

  • Re: semi-colon suppress output of user defined function
    ... > The problem you're having is that the semicolon suppresses OUTPUT. ... > It sounds like you're implementing a 'verbose' option to your function,> and this should be done via an optional argument, not the semicolon> supression. ... and let the logging function determine what information to write and to where it should be written (screen if verbose is 'display', a log file if verbose is 'logging', etc.) To add a new log destination or logging "level" in the future all you need to do is modify the one logDiagnostics function rather than dozens or hundreds of uses of "if verbose". ...
    (comp.soft-sys.matlab)
  • Re: Startup panes
    ... result wasn't all that verbose after all. ... "Anthony Yates" wrote in message ... > machines would display them and others not. ...
    (microsoft.public.win2000.general)
  • Re: Startup panes
    ... result wasn't all that verbose after all. ... "Anthony Yates" wrote in message ... > machines would display them and others not. ...
    (microsoft.public.win2000.group_policy)
  • lvm lvdisplay -v vg01/home does not display physical extents
    ... I've been using LVM for a while now (mostly on HPUX PARISC ... display of physical extents if lvdisplay -v group/lvmgroup was passed. ... Instead of be verbose (as it is ...
    (alt.os.linux.suse)