Suppress function output

前端 未结 3 1044
南旧
南旧 2020-12-19 11:57

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

My problem is that I always get this:

>>function(\'funct         


        
相关标签:
3条回答
  • 2020-12-19 12:23

    The simplest way to avoid having output printed out is to not assign the first output argument if no output argument was requested:

    function [aOut,b,c] = doSomething
    
    %# create a,b,c normally
    a = 1;
    b = 4;
    c = 3;
    
    %# only assign aOut if any output is requested
    if nargout > 0
       aOut = a;
    end
    
    0 讨论(0)
  • 2020-12-19 12:33

    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.

    0 讨论(0)
  • 2020-12-19 12:38

    You could try using the diary functionality. It redirects all input and output from the command prompt to a file of your choice. If you only turn it on during a specific function, no input should be captured. I admit it is a bit of a clumsy solution as the diary on/off state is global to matlab, but it might be ok in your case.

    Read more about it here: Diary matlab help

    0 讨论(0)
提交回复
热议问题