0
votes

I am learning to use matlab. In the following code I want to apply the mldivide function https://www.mathworks.com/help/matlab/ref/mldivide.html However, I am a little confused on how a function handles outputs. According to the documentation https://www.mathworks.com/help/matlab/ref/function.html when I call my function in the command window I should have out1, out2, and out3 spat out to me. But only out1 is displayed. Why?

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
The page you linked has the right syntax, right under the heading "Function with Multiple Outputs" in the "Examples" section: mathworks.com/help/matlab/ref/function.html#btexm36Cris Luengo

1 Answers

1
votes

Because you di not assign the output. Therefore, the function returns only the first output. If you call [out1, out2, out3] = testSystem(2,3,-10), it should do what you want.