return multiple output variables from Matlab function

后端 未结 4 1302
既然无缘
既然无缘 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:57

    Matlab function outputs are in cell format, so you can define a cell data with the size same as the function output and use it as a single variable to store all the outputs in a more structured way :)

    a = cell{3, 1};
    [a{:}] = test(x, y, z);
    A = a{1};
    B = a{2};
    C = a{3}; 
    

提交回复
热议问题