[R] 3D array was L(x,y,t)?

Bill Simpson wsi at gcal.ac.uk
Thu May 4 10:11:17 CEST 2000


This is what I wound up doing to create a 3D array: I used outer to create
a 2D array, and used a loop around outer to handle the third index.

I guess R/S only has constructs for fast 2D array handling (e.g. outer).
If you have higher dimensional arrays you apply outer() to 2D portions of
them.

I would appreciate any improvements over my solution.

corr.contrast3<-function(v0=.01, v1=-.01, phase=0)
{
#uses 3D rep of signals: s0(x,y,t)
#note corr=0 if v1=v0+pi/2 (orthogonal)
x<-seq(1,66)
y<-seq(1,31)
z0<-rep(0,66*31*19)
dim(z0)<-c(66,31,19)   
z1<-z0

f0<-function(x,y,time) .45*cos(2*pi*3*x/66+v0*time)
f1<-function(x,y,time) .45*cos(2*pi*3*x/66+v1*time+phase)

for(time in seq(1,19))
        {
        z0[,,time]<-outer(x,y,f0,time)
        z1[,,time]<-outer(x,y,f1,time)
        }
    
energy<-sum(z0^2+z1^2)/2   
corr<-sum(z0*z1)/energy
        
list(corr=corr,energy=energy)
}

Bill

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list