return multiple output variables from Matlab function

后端 未结 4 1346
既然无缘
既然无缘 2021-01-02 07:11

Lets say I have a function:

function [ A, B, C ] = test(x, y, z)
    A=2*x;
    B=2*y;
    C=2*z;
end

When you press run, Matlab returns on

4条回答
  •  情书的邮戳
    2021-01-02 07:51

    MATLAB will automatically ouput the variables/expressions those are not end with a ';'.

    So if you just need to display all these values, the simplest way will be:

    function [ A, B, C ] = test(x, y, z)
        A=2*x    % no ';' will print A's value automatically
        B=2*y    % no ';' will print B's value automatically
        C=2*z    % no ';' will print C's value automatically
    end
    

提交回复
热议问题