DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace negative values in multiple channels with ''0'.

Solved!
Go to solution

Hello

 

I am calculating, and then creating a cumulative channel of, multiple channels. The negative values in these channels are not needed, and I need a nice way to replace every negative value in these channels with a value of '0'.

 

My current code is:

 

  Do
   Do
     If Data.Root.ChannelGroups(2).Channels(i).Values(ii) < 0 Then Data.Root.ChannelGroups(2).Channels(i).Values(ii) = 0      
      ii = ii + 1
   Loop until ii > Data.Root.ChannelGroups(2).Channels(i).Properties("length").Value
    ii = 1
    i = i + 1
  Loop until i > Data.Root.ChannelGroups(2).Channels.Count

 

It works, but I don't like it. It adds several seconds to my script's runtime, which was nearly instantaneous. Is there any better way to do this?

 

Thanks.

0 Kudos
Message 1 of 3
(4,430 Views)
Solution
Accepted by topic author Kevin_McG

Hello Kevin,

 

The fastest way to go through a channel and check for values smaller or equal to 0 is through the Channel Calculator. The code below takes all channel from the first channel group (with the exception of the first channel which happens to be the time channel in my example data set) and replaces values <0 with 0 through the IIF function.

 

Set Group = Data.Root.ChannelGroups(1)
iMax = Group.Channels.Count
FOR i = 2 TO iMax
  Set Channel = Group.Channels(i)
  Formula = "y = IIF(y<0, 0, y)"
  Call Calculate(Formula, Array("y"), Array(Channel))
NEXT ' i

In this example we overwrite the existing channel data values with 0, but you could also copy the channels to make sure your raw data stays available to you.

 

The channel calculator is extremely fast for this type of operation because it doesn't create a loop to go though each line separately and check values there ...

 

I hope this is helpful,

 

     Otmar

Otmar D. Foehner
0 Kudos
Message 2 of 3
(4,424 Views)

Ah, yes. I forgot about that. I made some small tweaks, but that's exactly the direction I needed.

 

Thanks, Otmar.

0 Kudos
Message 3 of 3
(4,398 Views)