DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Solved!
Go to solution

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.

Thanks in Advance.

0 Kudos
Message 1 of 4
(2,870 Views)
Solution
Accepted by topic author Kandukuri_raghavendra
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 resChn = Data.Root.ChannelGroups.Add("result").Channels.Add("result indexes", DataTypeChnFloat64)
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

Capture22.JPG

Message 2 of 4
(2,858 Views)

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

0 Kudos
Message 3 of 4
(2,850 Views)

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()
Set oGrp = Data.Root.ChannelGroups.Add("MyChnGrp1")
Set oChnA = oGrp.Channels.Add("ChnA",DataTypeChnFloat64)
Set oChnB = oGrp.Channels.Add("ChnB",DataTypeChnFloat64)
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"
Set arrValues(0) = oGrp.Channels.Add("ChnA_GT_ChnB",DataTypeChnFloat64)
arrSymbols(1) = "A"
Set arrValues(1) = oChnA
arrSymbols(2) = "B"
Set arrValues(2) = oChnB
Call Calculate(sFormula, arrSymbols, arrValues)

 

Message 4 of 4
(2,763 Views)