Re: do I need this IF statement? [message #43238] |
Thu, 24 March 2005 07:29  |
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/
|
|
|