multidimensional cell-based bsxfun generalization

版本 1.0.0.0 (4.2 KB) 作者: michaelB brost
Preliminary M-ary singleton expansion based upon cell arrays sequentially sent to user function.
2.0K 次下载
更新时间 2009/3/24

无许可证

Preliminary release of a generalization of bsxfun to cell arrays of arbitrary length, arbitrary number and arbitrary contents.

The cell arrays may contain virtually any matlab object: numbers, arrays, strings, structures etc.

The user supplied function should handle the inputs as presented (using a try-catch block preferably) or return an identifiable default value such as nan, [] or 0 etc. on failure.

Example:
x = {rand(20), rand(20), rand(20)};
y = {rand(20), rand(20)};
z = {rand(20), rand(20)};

Save the following file myFunc1.m:
function res = myFunc1(varargin)
res=[];
try,
res=varargin{1}*varargin{2}*varargin{3};
end

xyz=mAryCellFcn(@myFunc1, x, y, z)

this results in a cell array of size 3x2x2 composed of 20x20 doubles.

example:
by choosing various values of N from 100 to 1000 and setting

x={1,2,3,4,.....N}
y=x;

and saving the following as myFunc3.m:
function res = myFunc3(varargin)
res=[];
try,
res=varargin{1}*varargin{2};
end

the execution time is as given in the screen shot. The time on the order of 25 seconds for N=1000 results from allocating 1,000,000 empty cells and then populating them by calling myFunc3 one million times. 1000 times for each of x, and 1000 times for each of y.

Acknowledged limitations:
This function will not handle anonymous functions.
Additional error trapping is probably useful.
Other limitations are TBD.

Additional examples are available by invoking mAryCellFcn with no inputs.

I'd like constructive criticisms and suggestions rather than pompous, self-important ramblings.

引用格式

michaelB brost (2024). multidimensional cell-based bsxfun generalization (https://www.mathworks.com/matlabcentral/fileexchange/23409-multidimensional-cell-based-bsxfun-generalization), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2007a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Random Number Generation 的更多信息
标签 添加标签

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0