06-19-2014 07:22 AM
Dear anyone,
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.
Regards,
X. Ignatius
Solved! Go to Solution.
06-19-2014 07:39 AM
Hi,
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.
Simyfren
06-19-2014 07:52 AM
Dear simy,
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,
X. Ignatius
06-19-2014 08:27 AM
oh,
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)
Call datablcopy("[2]/[2]",Time_interval(i),length(i)+1,"Torque1")
Call chnsum("Torque1","Torque1_1")
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
'
'
next
'__________________________________________________
where length() and Time_interval() are arrays (in the case when this values are different for each group).
Hope this helps!
Simyfren
06-20-2014 01:18 AM
Dear Simy,
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.
Regards,
X. Ignatius
06-20-2014 01:43 AM
Hi,
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.
Simyfren
06-20-2014 03:31 AM
Hi Simy,
This is what I tried but it is not working. What could be the reason for it?
Regards,
X. Ignatius
06-20-2014 03:35 AM
And what is wrong?
Did you get some error?
Simyfren
06-20-2014 03:51 AM
Simy,
I couldn't find out what was wrong. Attached the error screen for reference.
Regards,
X. Ignatius
06-20-2014 03:51 AM
Simy,
I couldn't find out what was wrong. Attached the error screen for reference.
Regards,
X. Ignatius