Directly, no. Unfortunately, there are a number of functions that are not available through anonymous functions, and one of them is access to several output arguments. (Another that I often find is that you cannot define an if inside an anonymous function. This is most likely the Matlab syntax more than anything else.
However, a fairly simple helper function can make this possible.
function varargout = get_outputs(fn, ixsOutputs) output_cell = cell(1,max(ixsOutputs)); [output_cell{:}] = (fn()); varargout = output_cell(ixsOutputs);
This function takes a function descriptor plus an array of output indices and returns indexed outputs.
If you create this file (hopefully better comment) and put it in your path, you can access the second output of the find function, as by defining the following function
find_2nd = @(x)get_outputs(@()find(x),2)
And now you can find the indexes of the array that are 1 as
>> find_2nd([4 3 2 1]==1) ans = 4
And now you can access alternative at-will output arguments from anonymous functions.
Pursuit
source share