MATLAB Language Functions Multiple outputs


Example

The following MATLAB script shows how to return multiple outputs in a single function:

myFun.m:

    function [out1, out2, out3] = myFun(arg0, arg1)
        out1 = arg0 + arg1;
        out2 = arg0 * arg1;
        out3 = arg0 - arg1;
    end

terminal:

    >> [res1, res2, res3] = myFun(10, 20)

    res1 =

            30

    res2 =

            200

    res3 =
            -10

However MATLAB will return only the first value when assigned to a single variable

    >> res = myFun(10, 20)

    res =

            30

The following example shows how to get a specific output

    >> [~, res] = myFun(10, 20)

    res =

            200