I have written a code which calculates averages for 26 different groups. Attached the sample code in .txt file for reference. I would like to put it in a FOR loop to avoid writing a lenghthier code to calculate averages for 26 different groups. Attached code contains average calculation for 2 groups.
Request you to help for the same.
Solved! Go to Solution.
I'm very confused with your code. Do you want to have averages for 26 different groups in one group or in 26 groups? You don't have to copy values for new channel and delete the channels then. Simply use chd to get values from channels.
I would take a specific block of the 2nd channel of each group, compute the average and store it in the channel name Torque_avg in the same group.
Have to repeat this for each 26 group and store the averages in their respective groups. Hope you understood now.
I appologize if I am not clear in the first post.
Thanks and Regards,
I see now.
Try something like this:
for i = 1 to 26
Call ChnAlloc("Torque" & i, length(i)+1, 1, DataTypeFloat64, "Numeric",2)
Call ChnAlloc("Torque"&i&"_1",length(i)+1, 1, DataTypeFloat64, "Numeric",2)
Call ChnAlloc("Torque_Avg",3, 1, DataTypeFloat64, "Numeric",2)
LastRow = cch("Torque1_1",2)
Avg1 = LastRow/(length(i)+1)
Avg1 = Avg1 - Tare_avg
chd(1,"Torque_Avg") = Avg1
chd(1,"T1") = Avg1
'rest of average calculation
where length() and Time_interval() are arrays (in the case when this values are different for each group).
Hope this helps!
Thanks for the input.
Still I have problem with the data block copy command. How to reference the group when I use it inside the FOR loop.
I cannot have unique channel names, as it would changes from test to test.
I cannot have unique group names, as it changes from test to test.
Could you help in this regard.
group referencing should look this ways:
"[i]/channelname" 'if the channel name is the same
"[i]/[j]" 'if the channel order is the same
Hope this helps, if not, give me a concrete example what do you want.