Reputation: 99606
From Mathworks
An anonymous function consists of a single MATLAB expression and any number of input and output arguments.
I wonder how an anonymous function can have more than one output arguments? Thanks and regards!
Upvotes: 3
Views: 374
Reputation: 17217
You can easily return multiple values from an anonymous function using deal
:
meanAndStd = @(x)deal(mean(x), std(x));
[meanValue, stdValue] = meanAndStd(randn(1000));
Upvotes: 0
Reputation: 11915
When the expression which your anonymous function is executing can return more than one value, then so can your anonymous function. For example, using the max function which can return both the max value of an array and its index:
arr = [1 2 4 3];
anon = @(y) max(y);
[maxVal, ind] = anon(arr);
Upvotes: 7