Code covered by the BSD License  

Highlights from
REPOP -- efficient replicating n-d array operations

Be the first to rate this file! 1 Download (last 30 days) File Size: 33.75 KB File ID: #16276

REPOP -- efficient replicating n-d array operations

by Jason Farquhar

 

07 Sep 2007 (Updated 13 Oct 2010)

REPOP -- any element-wise operator between different sized n-d matrices without memory copies

| Watch this File

File Information
Description

Replicating arithmetical and logical operators.

Does element by element operations on X and Y where non-same sized dimensions are implicity wrapped round to match the size of the larger
to give a result matrix Z with size max(size(X),size(Y));

In general this is at least 2x faster than the equivalent matlab code using repmats and has the advantage of requiring no additional memory.

 Example Usage:
     X = randn(10000,10); example signal with data in rows
     stdX = repop(X,mean(X,1),'-'); subtract the mean vector
     stdX = repop(stdX,std(stdX,0,1),'/'); % divide by std-deviation

Operator can be one of:

Arthemetical -- returns a double matrix
   '+','.+',plus - Implicitly repmatted elementwise addition
   '-','.-',minus - Implicitly repmatted elementwise addition
   '*','.*',times - Implicitly repmatted elementwise multiplication
   '^','.^',power - Implicitly repmatted elementwise raise X to power Y
   '\','.\',ldivide- Implicitly repmatted elementwise divide Y by X
   '/','./',rdivide- Implicitly repmatted elementwise divide X by Y

Relational -- returns a logical matrix
N.B. for complex inputs the <,>,<=,>= operators are based upon abs(x)
 (not real(x) as in matlab)
   '==',eq - Implicitly repmatted elementwise equality
   '~=',ne - Implicitly repmatted elementwise dis-equality
   '<' ,lt - Implicitly repmatted elementwise less than
   '>' ,gt - Implicitly repmatted elementwise greater than
   '<=',le - Implicitly repmatted elementwise less than equal
   '>=',ge - Implicitly repmatted elementwise greater than equal

MATLAB release MATLAB 6.5 (R13)
Other requirements MEX compiliation must be working. This means a c-compilier must be installed.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
07 Sep 2007 h User

In R2007a and newer check out bsxfun.

15 Oct 2010 Rody Oldenhuis

That's exactly what I wanted to say :) Although bsxfun() is even better, since it can do its calculations in parallel on multicore computers.

Please login to add a comment or rating.
Updates
21 Sep 2007

modified to only replicate non-unit dimensions if explicitly wanted.

18 Jan 2008

Some bug fixes -- particularly for mixed real and complex inputs.
Also partially modified to support other than double input matrices types.

19 Feb 2008

Added support of single and mixed single/double inputs

12 Jun 2008

Bug fixes -- particularly for the mixed double/single inputs

27 Jun 2008

bug fixes to memory management errors
added mod,min,max to the set of operators

12 Oct 2010

Some minor code updates to make build better with 64bit macs.

13 Oct 2010

Fixed bug with the repop(x,'op',y) calling convention

13 Oct 2010

bug fix update

Tag Activity for this File
Tag Applied By Date/Time
matrices Jason Farquhar 22 Oct 2008 09:26:03
replicating array operations Jason Farquhar 22 Oct 2008 09:26:03

Contact us at files@mathworks.com