I'm afraid there's no such equivalent for cell-arrays :-(
As far as I can see, you can either:
- Follow Oleg's suggestion and use loops
- Use existing implementations such as
mAryCellFcn
orfrom the File Exchange.csxfun
Roll your own function. For example, here's a variant of Robert's idea that works for inputs of any dimensions (under the restrictions of
bsxfun
, of course) and an arbitrary binary functionfunc
:function C = mybsxfun(func, A, B) idx_A = reshape(1:numel(A), size(A)); idx_B = reshape(1:numel(B), size(B)); C = bsxfun(@(ii, jj)func(A(ii), B(jj)), idx_A, idx_B);
If your function can operate on entire cell arrays element-wise, you could perform a singleton expansion on your cell arrays first, and then feed them directly to the function
func
:mask = bsxfun(@or, true(size(A)), true(size(B))); idx_A = bsxfun(@times, mask, reshape(1:numel(A), size(A))); idx_B = bsxfun(@times, mask, reshape(1:numel(B), size(B))); C = func(A(idx_A), B(idx_B));
The latter method might be faster if
func
is optimized for vectorized operations on cell arrays.