comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » correlation matrix
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
correlation matrix [message #35323] Wed, 11 June 2003 12:04 Go to next message
kevinlausten is currently offline  kevinlausten
Messages: 6
Registered: April 2003
Junior Member
I have written code to create the correlation matix of a data cube,
however, it seems to run slower than I would expect. I am I doing
anything inefficiently?

for r = 0, (nrows-1) do begin
for c = 0, (ncols-1) do begin
;sum = 0
for bb = 0, (nbands-1) do begin
ref(bb) = in_cube(bb, c, r)
; 'ref' equals 'back_cube' for all values of 'bb' at location
; (c, r)
endfor
;print, ref
temp = ref#transpose(ref)
; 'temp' equals the product of 'ref' and the transpose of 'ref'
sum = sum + temp
; 'sum' is a running total of the value of 'temp' at location
; (c, r)
endfor
endfor
final0 = fltarr(nbands, nbands)
; 'final0' is a floating point aray of size (nbands, nbands)
n = npixels
; 'n' is a variable equal to 'npixels'
final0= sum/n
; final0 is correlation matrix
Thanks
Kevin
Re: correlation matrix [message #35462 is a reply to message #35323] Wed, 11 June 2003 18:18 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
kevinlausten@hotmail.com (Kevin M. Lausten) writes:
> I have written code to create the correlation matix of a data cube,
> however, it seems to run slower than I would expect. I am I doing
> anything inefficiently?
>
> for r = 0, (nrows-1) do begin
> for c = 0, (ncols-1) do begin
> ;sum = 0
> for bb = 0, (nbands-1) do begin
> ref(bb) = in_cube(bb, c, r)
> ; 'ref' equals 'back_cube' for all values of 'bb' at location
> ; (c, r)
> endfor

Whatever the IN_CUBE() is, it will be the limiting factor in your
snippet, since it is in the innermost loop. If you can vectorize
IN_CUBE over BB then your routine should be faster.

Good luck,
Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Redirect STDOUT
Next Topic: IDL and DODS (OpenDAP) data?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 03:56:28 PDT 2025

Total time taken to generate the page: 2.00006 seconds