File Exchange

image thumbnail

bsxfun substitute

version 1.0.0.0 (6.38 KB) by Douglas Schwarz
Substitute for bsxfun for older versions of MATLAB in which it is not built-in.

2 Downloads

Updated 17 Feb 2009

View License

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.

Comments and Ratings (3)

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.

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

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

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Generalized Array Operations