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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: do I need this IF statement? [message #43238] Thu, 24 March 2005 07:29
Benjamin Luethi is currently offline  Benjamin Luethi
Messages: 22
Registered: December 2004
Junior Member
Hi again,

Just realized that d = SQRT(x(INDGEN(M))^2 + y(INDGEN(N))^2) isn't giving
you the desired matrix (it's just a vector). But

d = SQRT( (x(INDGEN(M))#replicate(1,N))^2
+ (y(INDGEN(N))#replicate(1,M))^2 )

should work...

Ben

On Thu, 24 Mar 2005 16:05:52 +0100, Benjamin Luethi <luethi@phim.unibe.ch>
wrote:

> 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/
Re: do I need this IF statement? [message #43241 is a reply to message #43238] Thu, 24 March 2005 07:05 Go 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/
Re: do I need this IF statement? [message #43246 is a reply to message #43241] Thu, 24 March 2005 04:48 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Margrethe writes:

> 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

JD has me totally intimidated about making sweeping generalizations,
but I'm going to state emphatically that you NEED the IF statement.
We'll see if that turns out to be true. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
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 13:53:42 PDT 2025

Total time taken to generate the page: 0.00598 seconds