02-10-2016 01:34 PM
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.
Solved! Go to Solution.
02-10-2016 03:22 PM
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
02-11-2016 02:39 PM
Ah, yes. I forgot about that. I made some small tweaks, but that's exactly the direction I needed.
Thanks, Otmar.