Be the first to rate this file! 79 downloads (last 30 days) File Size: 18.5 KB File ID: #23409

multidimensional cell-based bsxfun generalization

by michaelB brost

 

24 Mar 2009

No BSD License  

Preliminary M-ary singleton expansion based upon cell arrays sequentially sent to user function.

Download Now | Watch this File

File Information
Description

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.

MATLAB release MATLAB 7.4 (R2007a)
Other requirements self contained mex file which can be compiled from the matlab command line. Compiled under Microsoft visual c++ 2003 and 2005
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
25 Mar 2009 michaelB brost

Does anyone have example mex c/c++ code for rev. 2007a or later which demonstrates how to invoke an anonymous function defined in the caller's workspace from a mex called from the same workspace??? Thanks mike

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
cell michaelB brost 24 Mar 2009 13:41:29
bsxfun michaelB brost 24 Mar 2009 13:41:29
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com