Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

matlab - Suppress function output

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...