MATLAB Language Functions Multiple outputs

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any MATLAB Language Question?