MATLAB: Arrayfun scalar expansion (non-uniform output)

arrayfun scalar_expansion singleton_expansion

I have a function that takes several scalar variables and outputs an array. The size of this array is always the same. I want to make a sweep of a few of the variables and store the output in a cell array.
According to documentation, arrayfun on GPUs support scalar expansion:
"A = arrayfun(FUN, B, C, …) evaluates FUN using elements of arrays B, C, … as input arguments with singleton expansion enabled. The inputs B, C, … must all have the same size or be scalar. Any scalar inputs are scalar expanded before being input to the function FUN." http://www.mathworks.com/help/distcomp/arrayfun.html
But unfortunately this is not the case for MATLAB arrayfun. Is there an easy way around this?
Here is some code to illustrate what I'm trying to do:
% Declare some constants
const1 = 1;
const2 = 2;
const3 = 3;
const4 = 4;
% Declare variables to sweep
sweep1 = 0:0.001:1;
sweep2 = 0:0.01:1;
[mat1, mat2] = meshgrid(sweep1, sweep2);
% What I want to do, but can't
% output is a 2D cell array
[output] = arrayfun(@function, mat1, mat2, const1, const2, const3, const4, 'UniformOutput', false);
% What I end up having to do
expander = ones(size(mat1));
const1 = const1(expander);
const2 = const2(expander);
const3 = const3(expander);
const4 = const4(expander);
[output] = arrayfun(@function, mat1, mat2, const1, const2, const3, const4, 'UniformOutput', false);
What I have right now works, but when sweep1 and sweep2 become very large, the memory needed for manual requirement becomes impractical. Is there a way to avoid manually expanding the scalars into massive matrices?
Any help would be appreciated.

Best Answer

I might not fully understand your question, but why don't you do something like:
output = arrayfun( ...
@(m1,m2) myFunction(m1, m2, const1, const2, const3, const4), ...
mat1, mat2, 'UniformOutput', false ) ;