cancel
Showing results for
Did you mean:

Solved!
Go to solution

## How to compare the data in diadem channel line by line and store the result to an array/channel?

HI,
is there a way to compare the data in Diadem channels, like i have this two channels, lets say "ca_Cyl1PressurePeakMeanFiltered_Mpa" and "NewChnZ", i would like to do a comparison where i would like to check if the values of "ca_Cyl1PressurePeakMeanFiltered_Mpa" channel are greater than values of "NewChnZ" channel if so do nothing else flag the index of "ca_Cyl1PressurePeakMeanFiltered_Mpa" and store it to some new channel.

for example:
lets say if the channel "ca_Cyl1PressurePeakMeanFiltered_Mpa" has entries (12.56,12.80,12.66) and the channel "NewChnZ" has entries (12.5,12.5,12.4) then the 3rd  entry/index should be flagged and get to stored in to new channel.

Message 1 of 4
(198 Views)
Solution
Accepted by Kandukuri_raghavendra

## Re: How to compare the data in diadem channel line by line and store the result to an array/channel?

```Option Explicit  'Forces the explicit declaration of all the variables in a script.

dim chnl1, chnl2, resChn, resChn2, i
set chnl1 = Data.Root.ChannelGroups(1).Channels("Channel")
set chnl2 = Data.Root.ChannelGroups(1).Channels("Channel1")
set resChn2 = Data.Root.ChannelGroups("result").Channels.Add("result indexes 2", DataTypeChnFloat64)

' When is chnl1 > chnl2 ?
for i = 1 to chnl1.Size step 1
if(chnl1.Values(i) > chnl2.Values(i)) then
resChn.Values(resChn.Size + 1) = i
resChn2.Values(resChn2.Size + 1) = i
else
resChn.Values(resChn.Size + 1) = NOVALUE
end if
next```

Message 2 of 4
(186 Views)

## Re: How to compare the data in diadem channel line by line and store the result to an array/channel?

Thank you @gsklyr, that's exactly what i was looking for.

Message 3 of 4
(178 Views)
Highlighted

## Re: How to compare the data in diadem channel line by line and store the result to an array/channel?

You can compare the channel values in two ways, one within a script, and another using the Analysis panel channel event search dialog (see http://www.savvydiademsolutions.com/analysis.php?topic=event-search-free-formula).

In a script, use the Calculate() command for the best speed, and always use the numeric comparison functions ValGT, ValEqualGL, ... instead of ">", "=>", etc. with floating point channels.  Below is an example.

Dim oGrp, oChnA, oChnB, sFormula
Call Data.Root.Clear()
oChnA.Values(1) = 12.015: oChnB.Values(1) = 12.0
oChnA.Values(2) = 55: oChnB.Values(2) = 56
oChnA.Values(3) = 0.0002359: oChnB.Values(3) = 0.0002360
oChnA.Values(4) = -204.95: oChnB.Values(4) = -205.01
'It is considerably faster to perform a comparision of channels using Calculate()
'You should always use the functions ValGT, ValEqualGT(), .. when you compare real
'(floating point) channel values (datatype DataTypeChnFloat64), otherwise you may
'sometimes get a result you wouldn't expect.
'The formula below assigns a value of one to the new channel R when the condition is met
'(value of oChnA > oChnB), and a value of zero otherwise.
sFormula = "R = IIF(ValGT(A,B),1,0)"
ReDim arrSymbols(2): ReDim arrValues(2)
arrSymbols(0) = "R"