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

Home » Public Forums » archive » help with 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
help with IF statement [message #90059] Wed, 21 January 2015 09:26 Go to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Hi

I need some help with an IF statement because I suspect that it's not doing what I really wish to do.

I have a 3D array [120,200,200] which contains my data. Then I am using this matrix to create another matrix. My code looks like this

DataArray ; contains the 3D data
Mean = total(DataArray[0:4,*,*],1)/5.

for i = 0, 199 do begin
for j = 0, 199 do begin
Barray = DataArray[*,i,j] - Array[i,j]
IF (TOTAL(Barray LT 0)) GT 0 THEN NEW_DATA[*,j,k] = Mean[j,k] $
ELSE NEW_DATA[*,j,k] = Mean[j,k] + OTHER
endfor
endfor

What I wanted to achieve with the above is that if an entry in the Barray has a negative value then the New_Data it's equals the mean otherwise NEW_DATA= Mean+ OTHER.
My data are images and when I display the images after that I found out that in places that there are not negative numbers the new_data array equals the mean only not the whole expression (Mean[j,k] + OTHER). Why this happened? It supposed to use the mean only when there are negatives.
Re: help with IF statement [message #90062 is a reply to message #90059] Wed, 21 January 2015 16:07 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
If I am reading it right, your code seems to match your description. Someone here used to say that this usually means there is something wrong with your assumptions about your arrays.

I would suggest checking the types, dimensions and values of some of the relevant expressions in your code, such as barray, other, dataarray[*,i,j], array[i,j], new_data[*,j,k] and mean[j,k]

By the way, are the expressions with new_data and mean supposed to be indexed by j and k? Not j and i? There is nothing in this code fragment setting the value of k. If it is really k, check that j and k were not swapped.

Paulo

On Wednesday, January 21, 2015 at 3:26:59 PM UTC-2, g.na...@gmail.com wrote:
> Hi
>
> I need some help with an IF statement because I suspect that it's not doing what I really wish to do.
>
> I have a 3D array [120,200,200] which contains my data. Then I am using this matrix to create another matrix. My code looks like this
>
> DataArray ; contains the 3D data
> Mean = total(DataArray[0:4,*,*],1)/5.
>
> for i = 0, 199 do begin
> for j = 0, 199 do begin
> Barray = DataArray[*,i,j] - Array[i,j]
> IF (TOTAL(Barray LT 0)) GT 0 THEN NEW_DATA[*,j,k] = Mean[j,k] $
> ELSE NEW_DATA[*,j,k] = Mean[j,k] + OTHER
> endfor
> endfor
>
> What I wanted to achieve with the above is that if an entry in the Barray has a negative value then the New_Data it's equals the mean otherwise NEW_DATA= Mean+ OTHER.
> My data are images and when I display the images after that I found out that in places that there are not negative numbers the new_data array equals the mean only not the whole expression (Mean[j,k] + OTHER). Why this happened? It supposed to use the mean only when there are negatives.
Re: help with IF statement [message #90064 is a reply to message #90059] Thu, 22 January 2015 01:29 Go to previous message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Thanks for your suggestions I will take a look. Just to double check my code

Instead of this IF statement:
IF (TOTAL(Barray LT 0)) GT 0 THEN NEW_DATA[*,i,j] = Mean[i,j] $
ELSE NEW_DATA[*,i,j] = Mean[i,j] + OTHER

Replace it by this:
NEW_DATA[*,j,k] >= Mean[j,k] $

Still doing the same thing right?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Map method bug?
Next Topic: check for infinity

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

Current Time: Wed Oct 08 13:40:49 PDT 2025

Total time taken to generate the page: 0.00703 seconds