5.0

5.0 | 1 rating Rate this file 273 downloads (last 30 days) File Size: 7.25 KB File ID: #23005

bsxfun substitute

by Douglas Schwarz

 

17 Feb 2009

Code covered by BSD License  

Substitute for bsxfun for older versions of MATLAB in which it is not built-in.

Download Now | Watch this File

File Information
Description

This m-file and accompanying mex functions replicate the functionality of bsxfun for use in older versions of MATLAB prior to R2007a -- the first version that came with bsxfun built-in.

This code retains the important feature of not replicating any large arrays in order to perform its function.

Included is the source code for a series of mex functions that implement this functionality for several basic operators: plus, minus, times, etc. The function will work without these present albeit more slowly.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Generalized Array Operations

MATLAB release MATLAB 7.0.4 (R14SP2)
Other requirements Tested on Mac OS X and Windows XP.
Zip File Content  
Other Files bsx_mex.c,
bsxfun.m,
make_bsx_mex.m,
readme.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
18 Feb 2009 Wolfgang Schwanghart

Hi Doug,

I didn't test your submission, since I have a version of Matlab, that includes bsxfun. Yet, it came to my mind that there was a previous submission for the same purpose.

http://www.mathworks.com/matlabcentral/fileexchange/18685

Best regards,
Wolfgang

18 Feb 2009 Douglas Schwarz

Hi Wolfgang,

Yes, I am aware of that submission. It differs from mine in that it uses extra memory by expanding the input arrays until they are the same size. My submission will never do that (and might be slower as a result).

Doug

28 Feb 2009 Paolo de Leva

An excellent "hack". A smart, fast and computationally efficient replacement for BSXFUN which allowed me to ensure backward compatibility for the latest version of the ARRAYLAB toolbox:

http://www.mathworks.fr/matlabcentral/fileexchange/8773 http://www.mathworks.fr/matlabcentral/fileexchange/8782 http://www.mathworks.fr/matlabcentral/fileexchange/23084

Two other functions, available on MATLAB Central File Exchange, do approximately the same job as Doug's submission:

http://www.mathworks.com/matlabcentral/fileexchange/10333
http://www.mathworks.com/matlabcentral/fileexchange/18685

They both do it less efficiently as for memory usage, by temporarily allocating a significant amount of additional memory to expand the input arrays. As for the first one (GENOP), it is also slower than this one.

On behalf of all the users of pre-R2007a MATLAB releases, thank you very much Doug.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
bsxfun Douglas Schwarz 17 Feb 2009 17:44:12
array expansion Douglas Schwarz 17 Feb 2009 17:44:12
singleton Douglas Schwarz 17 Feb 2009 17:44:12
singleton expansion Paolo de Leva 28 Feb 2009 07:28:16
virtual expansion Paolo de Leva 28 Feb 2009 07:28:17
virtual replication Paolo de Leva 28 Feb 2009 07:28:17
array replication Paolo de Leva 28 Feb 2009 07:28:17
replication Paolo de Leva 28 Feb 2009 07:29:28
expansion Paolo de Leva 28 Feb 2009 07:29:28
elementwise operation Paolo de Leva 28 Feb 2009 07:29:28
algebraic operation Paolo de Leva 28 Feb 2009 07:29:28
relational operation Paolo de Leva 28 Feb 2009 07:29:28
eq Paolo de Leva 28 Feb 2009 07:39:09
array Paolo de Leva 28 Feb 2009 07:39:09
atan2 Paolo de Leva 28 Feb 2009 07:39:09
bsxfun Paolo de Leva 28 Feb 2009 07:39:09
arithmetic operation Paolo de Leva 28 Feb 2009 07:39:09
vector expansion Paolo de Leva 28 Feb 2009 07:39:09
gt Paolo de Leva 28 Feb 2009 07:39:09
ldivide Paolo de Leva 28 Feb 2009 07:39:09
le Paolo de Leva 28 Feb 2009 07:39:09
lt Paolo de Leva 28 Feb 2009 07:39:09
matrix expansion Paolo de Leva 28 Feb 2009 07:39:09
minus Paolo de Leva 28 Feb 2009 07:39:09
multidimensional array Paolo de Leva 28 Feb 2009 07:39:09
multiplication Paolo de Leva 28 Feb 2009 07:39:09
ne Paolo de Leva 28 Feb 2009 07:39:09
plus Paolo de Leva 28 Feb 2009 07:39:09
power Paolo de Leva 28 Feb 2009 07:39:09
product Paolo de Leva 28 Feb 2009 07:39:09
rdivide Paolo de Leva 28 Feb 2009 07:39:09
times Paolo de Leva 28 Feb 2009 07:39:09
ge Paolo de Leva 28 Feb 2009 07:39:09
array expansion Paolo de Leva 28 Feb 2009 07:40:02
singleton Paolo de Leva 28 Feb 2009 07:40:05
 

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