Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...