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

Home » Public Forums » archive » Re: do I need this IF statement?
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: do I need this IF statement? [message #43241 is a reply to message #43238] Thu, 24 March 2005 07:05 Go to previous messageGo to previous message
Benjamin Luethi is currently offline  Benjamin Luethi
Messages: 22
Registered: December 2004
Junior Member
Hi,

No, if I understand your program correctly: You're adding all image
values that are closer than 3sigma (to be precise you weigh each value
with p before adding).

You can achieve the same with the following 4 lines:

d = SQRT(x(INDGEN(M))^2 + y(INDGEN(N))^2)
usable = d lt 3.*sigma

p = some_function( x(INDGEN(M)), y(INDGEN(N)) )

profile = TOTAL( usable * p * image )

If a position (x(i),y(j)) is further away than 3sigma then usable[i,j]
is zero and thus the image value is not added to the profile.

I don't know what you do in v = v1 + vr(i,indx). It doesn't make sense
since v is overwritten in each loop and never used anyway...

And note:
if y has N elements then you can write y instead of y(INDGEN(N)).

This is a solution to this case - there might be some cases however,
where it's not that easy or even impossible.

Ben






On 24 Mar 2005 02:07:01 -0800, Margrethe <margrethewold@hotmail.com> wrote:

>
> I find that in some cases I really need an IF statement to make sure
> that I don't address some arrays with index -1. In the example below I
> have vectorized the inner loop over j, but have kept the loop over i.
> Is there a way to avoid the IF statement? Grateful for help! -Margrethe
>
> FOR i=0,N-1 DO BEGIN
>
> d = sqrt ( x(i) ^2 + y (INDGEN(N)) ^2 )
> indx = WHERE ( d LT 3.*sigma, ct )
>
> IF (ct GT 0) THEN BEGIN
>
> v = v1 + vr (i,indx)
> p = some_function ( x(i), y(indx) )
> profile = profile + TOTAL ( p * image(i,indx) )
>
> ENDIF
>
> ENDFOR
>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: paralel/serial ports
Next Topic: Still more fun with XML

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

Current Time: Wed Oct 08 18:03:37 PDT 2025

Total time taken to generate the page: 0.00414 seconds