not that i know of. subsref doesn't seem to work in this case, possibly because the second variable isn't even returned from the function.
since matlab 2009b it is possible to use the notation
[~, b] = function(x)
if you don't need the first argument, but this still uses a temporary variable for b.
Unless there is some pressing need to do this, I would probably advise against it. The clarity of your code will suffer. Storing the outputs in temporary variables and then passing these variables to another function will make your code cleaner, and the different ways you could do this are outlined here: How to elegantly ignore some return values of a MATLAB function?.
However, if you really want or need to do this, the only feasible way I can think of would be to create your own function secondreturnvalue. Here's a more general example called nth_output:
function value = nth_output(N,fcn,varargin)
[value{1:N}] = fcn(varargin{:});
value = value{N};
end
And you would call it by passing as inputs 1) the output argument number you want, 2) a function handle to myfunc, and 3) whatever input arguments you need to pass to myfunc:
abs(nth_output(2,@myfunc,x))
From the documentation of cellfun:
[A1,...,Am] = cellfun(func,C1,...,Cn) calls the function specified by function handle func and passes elements from cell arrays C1,...,Cn, where n is the number of inputs to function func. Output arrays A1,...,Am, where m is the number of outputs from function func, contain the combined outputs from the function calls.
So yes, cellfun can use a multi-output function and in this case it simply returns a number of outputs. If you want to use the second one only, you can use ~ to ignore the first one. The same goes for multiple outputs of anonymous functions - they will be returned if you specify multiple output arguments. Here is a simple code:
function test
x{1} = 1;
x{2} = 2;
[~, B] = cellfun(@foo, x);
f=@(c)foo(c);
[A, B] = f(1);
function [a b] = foo(x)
a = x+1;
b = x+2;
end
end
This can be done by using a cell array as the single output of the function, instead of a function with multiple outputs.
Define your function to return a cell array (or create an auxiliary function that calls the original multiple-output function):
function F = foo2(x)
[a,b,c] = foo(x);
F = {a, b, c};
end
And then you can create a handle that calls your function and gets only one of the cells from the cell array.
f = @(x) cell(foo2(x)){2} % This selects the second output
g = @(x) cell(foo2(x)){3} % This selects the third output
Which is almost exactly what you were asking for. You could even create a handle that returns the n-th output
f = @(x,n) cell(foo2(x)){n}