How to force MATLAB to return all values in a nested function call?

前端 未结 4 1167
太阳男子
太阳男子 2020-12-20 06:51

I find it impossible to write MATLAB code without creating a huge number of superfluous, single-use variables.

For example, suppose function foo returns

4条回答
  •  太阳男子
    2020-12-20 07:48

    You can replace the three variables by a cell array using a comma-separated list:

    vars = cell(1,3);     % initiallize cell array with as many elements as outputs of foo
    [vars{:}] = foo(5);   % comma-separated list: each cell acts as a variable that 
                          % receives an output of foo
    result = bar(vars);
    

提交回复
热议问题