Can an anonymous function contain multiple output arguments?
From Mathworks
An anonymous function consists of one MATLAB expression and any number of inputs and outputs.
I wonder how an anonymous function can have multiple output arguments? Thank you and welcome!
+3
Tim
source
to share
2 answers
When the expression that your anonymous function is executing can return more than one value, then your anonymous function can be. For example, using the max function , which can return both the maximum value of an array and its index:
arr = [1 2 4 3]; anon = @(y) max(y); [maxVal, ind] = anon(arr);
+7
goric
source
to share
You can easily return multiple values from an anonymous function with deal
:
meanAndStd = @(x)deal(mean(x), std(x)); [meanValue, stdValue] = meanAndStd(randn(1000));
0
bastibe
source
to share