Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress function output

Tags:

matlab

I have a short function which uses textscan to read data into a variable.

My problem is that I always get this:

>>function('function.txt')

    ans = 

        {10x1 cell}    {10x1 cell}    {10x1 cell}    [10x1 double]

Is there any way to suppress this, apart from adding a semi colon to the end of the line I use to call the function? I'd like to be able to suppress it without adding the semi colon. I don't want to display anything at all when running this function, I just want to load my file.

like image 752
Mark Hughes Avatar asked Jan 07 '13 04:01

Mark Hughes


1 Answers

You can suppress the output by remove output arguments (or return values) of the function. OR Try use Variable Number of Outputs, see Support Variable Number of Outputs

function varargout = foo
    nOutputs = nargout;
    varargout = cell(1,nOutputs);
    for k = 1:nOutputs;
        varargout{k} = k;
    end
end

You type >>foo and get nothing. You type >>a=foo and get >>a=1. You type >>[a,b]=foo and get >>a=1 >>b=2.

You can thus suppress output by NOT providing any output arguments.

like image 127
Richard Dong Avatar answered Oct 05 '22 21:10

Richard Dong