DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Finding a corresponding value in Y channel

Hi guys,

I have the following problem. I have several channels "Slip" and "Bondstress". The channels start at different times and the loading rate is not constant. I need to find a Bondstress that corresponds to a specific Slip and then make an average of the slip channels. I wrote the following code. I does what needs to be done, but is very slow as I would need aprox. 1000 vlaues in my LinearGenerated channel. The LinearGenerated channel containes the levels of Slip which I am interested in. Does anyone have an idea how to do it more elegant? I can't use the ChnAverage function as the channels have different time domain. I also tried linear mapping but couldn't make it work as the channels are not monotonically increasing - except of the LinearGenerated channel.

Thanks a lot in advance

 

dim i, n, iDeflection, iRowNo, oMyChn, oMyChnOld, oOldVerbund, oNewVerbund

for i=1 to 4
  Set oMyChn = Data.Root.ChannelGroups(i).Channels.Add("New schlupf", DataTypeFloat64)
  Set oMyChnOld = Data.Root.ChannelGroups(i).Channels("Schlupf")
  Set oOldVerbund = Data.Root.ChannelGroups(i).Channels("Verbundspannung")
  Set oNewVerbund = Data.Root.ChannelGroups(i).Channels.Add("New Verbundspannung", DataTypeFloat64)

    for n=1 to ChnLength(Data.Root.ChannelGroups(6).Channels("LinearGenerated"))
    iDeflection = Data.Root.ChannelGroups(6).Channels("LinearGenerated").values(n)
    iRowNo = ChnFind("Ch(""["&i &"]/Schlupf"")>="& str(iDeflection))
    oMyChn(n)= oMyChnOld(iRowNo)
    oNewVerbund(n) = oOldVerbund(iRowNo)
  next
next
0 Kudos
Message 1 of 5
(4,420 Views)

Hello,

 

could you please add some comments to your code?

 

In general what you are doing looks fine and I don't see a chance to make it more efficient. I guess, depending on how many values you are working with, this might just take some time.

 

Best regards,

Kathrin

 

0 Kudos
Message 2 of 5
(4,370 Views)

Hi, 

I am not very good at programming so please applogize the programming faults. I added some comments to the code. I think that writing the values in the new channels take a lot of time. In Matlab, I would create a temporary vector of rows I am interested in, and then I would just copy these rows from the  "Bondstress" channel in one block operation. But I am not sure how to do this in Diadem and if it would speed up the process. This script runs a few minutes. My channels have aprox. 30 000 values. It is also possible that finding the rows of interest takes a lot of time as well 😞

 

dim i, n, iDeflection, iRowNo, oMyChn, oMyChnOld, oOldVerbund, oNewVerbund

for i=1 to 4
    Set oMyChn = Data.Root.ChannelGroups(i).Channels.Add("New schlupf", DataTypeFloat64)
    Set oMyChnOld = Data.Root.ChannelGroups(i).Channels("Schlupf")    'Schlupf=slip
    Set oOldVerbund = Data.Root.ChannelGroups(i).Channels("Verbundspannung")  'Verbundspannung=bondstress
    Set oNewVerbund = Data.Root.ChannelGroups(i).Channels.Add("New Verbundspannung", DataTypeFloat64)

    for n=1 to ChnLength(Data.Root.ChannelGroups(6).Channels("LinearGenerated")) 'I have a generated channel containing slip values I am interested in - ca 500 values
    iDeflection = Data.Root.ChannelGroups(6).Channels("LinearGenerated").values(n)  
    iRowNo = ChnFind("Ch(""["&i &"]/Schlupf"")>="& str(iDeflection))  'For every row it looks into the channel of measured slips (that have corresponding bond stresses) and tries to find a deflection closest to my predefined deflection 
    oMyChn(n)= oMyChnOld(iRowNo) 'gets the accutal value of the slip and adds it to the new channel created at the beginning of the script
    oNewVerbund(n) = oOldVerbund(iRowNo) 'When I have the row Nr.of the slip I am interested in I look into the channel with corresponding Stresses and I write the stress into the new channel
  next
next

'After running this script, I have for all Samples in my Series 500 vlaues of slip and their corresponding stresses. So I can make an average from the stresses.

 

0 Kudos
Message 3 of 5
(4,364 Views)

Hi Dasein,

 

This edited version of your script should run faster.  I was unable to test it, though, so I might have introduced an error...

 

dim i, n, nMax, SlipGroup, Group, iDeflection, iRowNo, oMyChn, oMyChnOld, oOldVerbund, oNewVerbund

Set SlipGroup = Data.Root.ChannelGroups(6)
Set SlipChannel = SlipGroup.Channels("LinearGenerated")
nMax = ChnLength(SlipChannel)
for i = 1 to 4
  Set Group = Data.Root.ChannelGroups(i)
  Set oMyChnOld = Group.Channels("Schlupf")    'Schlupf=slip
  Set oOldVerbund = Group.Channels("Verbundspannung")  'Verbundspannung=bondstress
  Set oMyChn = Group.Channels.Add("New schlupf", DataTypeFloat64)
  Set oNewVerbund = Group.Channels.Add("New Verbundspannung", DataTypeFloat64)
  for n = 1 to nMax 'I have a generated channel containing slip values I am interested in - ca 500 values
    iDeflection = SlipChannel(n)  
    iRowNo = PNo(oMyChnOld, iDeflection) 'For every row it looks for the closest match
    oMyChn(n)= oMyChnOld(iRowNo) 'gets the accutal value of the slip and adds it to the new channel created at the beginning of the script
    oNewVerbund(n) = oOldVerbund(iRowNo) 'When I have the row Nr.of the slip I am interested in I look into the channel with corresponding Stresses and I write the stress into the new channel
  next
next

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 5
(4,354 Views)

Hi Brad,

thanks for your adjustments. Your modification of the code work fine, but it is still rather slow. Would there be any way how to store the rows of interest into an array in memory and then just coppy out those rows in one block operation from the respective channels?

Anyway thanks a lot for your help!

0 Kudos
Message 5 of 5
(4,338 Views)