Handles returning multiple outputs

24 次查看(过去 30 天)
I have a function handle that returns 3 values.
@f(x,y) = basis_handle(x,y);
[z, dx, dy] = f(0.1,0.1) %returns 3 vectors
what I'd like to do now is create a function handle that performs a dot product of each of those 3 vectors with another vector. Something like:
@f_2(x,y) c'*f(x,y) %c is a known vector, same size as ones returned by @f(x,y)
As it is, this handle returns only 1 value, even if I try to ask for more, i.e. this produces an error:
[z, dx, dy] = f_2(0.1,0.1)
Is there any way to create a function handle that returns all 3 values as requested?

采纳的回答

Alfonso Nieto-Castanon
I do not see how to do this using purely anonymous functions, but if that is not a requirement you could simply create a new function like:
function varargout=fevalndot(c,varargin)
[x{1:nargout}]=feval(varargin{:});
varargout=cellfun(@(x)c'*x,x,'uni',0);
end
and then simply define a handle to this function:
f_2 = @(x,y)fevalndot(c,f,x,y);
  1 个评论
Lukas
Lukas 2013-11-24
That's exactly what I ended up doing. It's a bit less slick, but it works well enough.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by