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

Home » Public Forums » archive » How to avoid the FOR loop when using TM_TEST?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: How to avoid the FOR loop when using TM_TEST? [message #55565 is a reply to message #55497] Sat, 25 August 2007 09:26 Go to previous messageGo to previous message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
wanglin1981@gmail.com wrote:
> I need to test the significance for each spatial point between two
> data sets (names are A(ix,iy,it1) and B(ix,iy,it2), ix and iy are
> spatial point, and it1 and it2 are temporal point) using the TM_TEST
> function. As the TM_TEST is not valid for two-dimentional matrix, I
> had to use the FOR loop as follows, which cost a lot of time.
>
> for j=0,iy-1 do begin
> for i=0,ix-1 do begin
> temp1=tm_test(A(i,j,*),B(i,j,*))
> sighl(i,j)=temp1(1)
> endfor
> endfor
>
> Is it possible to avoid the FOR loops?
>
> Thanks!
>

Lin,

Welcome to the group :).

For the code you have, you can get a significant speed up if you replace
it all (including the loops) with:

na=(size(a,/dim))[2]
nb=(size(b,/dim))[2]
meanx=total(a,3) / na
meany=total(b,3) / nb
df = 1.0*(na+nb-2)
t = (meanx-meany)/sqrt((((total((a-rebin(meanx,ix,iy,na))^2,3) + $
total((b-rebin(meany,ix,iy,nb))^2,3) )/df) * (1.0/na + 1.0/nb)))
sighl = ibeta(0.5*df,0.5,df/(df+t^2))

give or take some line breaks which I'm sure have been broken posting it
across a newsgroup.

This will give you s sighl array identical to the one you get with your
present code.

However, unless the speed is a real issue then your present solution is
much easier to read and maintain. Note also that this doesn't give any
of the other options which tm_test takes.

Good question; keep them coming.

Thanks,

Allan
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Syntax Error Confusion
Next Topic: Re: How to read ASTER in ENVI?

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

Current Time: Sun Oct 12 02:34:35 PDT 2025

Total time taken to generate the page: 1.27843 seconds