MATLAB: Passing array arguments to an anonymous function

anonymous functionsvector argument

I have an anonymous function, for example
f = @(x,y)x.^2.*y.^2
In general for my problem I don't know how many arguments f will have. Nor do I know how many elements each argument will have.
I want to pass in a single element as an argument. If x and y are scalars, I can define z = num2cell(x,y), then write
f(z{:})
But if x and y are vectors this doesn't work. I could write
for ii=1:2; z = { x(ii);y(ii) }; f(z{:}) ;end
but of course I want to avoid the loop.
Is there some efficient way to obtain what I want by writing something like
f(q{:})
where q{:} is a cell array with each cell containing a vector rather than a scalar.

Best Answer

It appears to me that what you want is arrayfun:
arrayfun(f, x, y)