为什么我的函数仅显示一个输出变量?

时间:2019-02-14 05:59:27

标签: matlab

我正在学习使用matlab。在下面的代码中,我想应用mldivide函数https://www.mathworks.com/help/matlab/ref/mldivide.html。但是,我对函数如何处理输出感到有些困惑。根据文档https://www.mathworks.com/help/matlab/ref/function.html,当我在命令窗口中调用函数时,我应该得到out1,out2和out3。但是仅显示out1。为什么?

function [out1, out2, out3] = testSystem(in1, in2, in3)

b = [in1; in2; in3];

A = [2, 1, 1; 
    -1, 1, -1;
    1,  2, 3;];

x = A\b;

disp(x);
out1 = x(1,1);
out2 = x(2,1);
out3 = x(3,1);

end
>> testSystem(2,3,-10)
     3
     1
    -5


ans =

     3

1 个答案:

答案 0 :(得分:1)

因为您没有分配输出。因此,该函数仅返回第一个输出。 如果您呼叫[out1, out2, out3] = testSystem(2,3,-10),它应该做您想做的事。

相关问题