Calling a Function with Multiple Outputs
The example below returns multiple values from a call to an anonymous function. Create anonymous function f that locates the nonzero elements of an array, and returns the row, column, and value of each element in variables row, col, and val:
f = @(X)find(X);
Call the function on matrix m using the function handle f. Because the function uses the MATLAB find function which returns up to three outputs, you can specify from 0 to 3 outputs in the call:
m = [3 2 0; -5 0 7; 0 0 1]
m =
3 2 0
-5 0 7
0 0 1
[row col val] = f(m);
val
val =
3
-5
2
7
1