DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

To put it in a FOR loop

Solved!
Go to solution

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

Download All
0 Kudos
Message 1 of 13
(5,816 Views)

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

 

0 Kudos
Message 2 of 13
(5,811 Views)

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

0 Kudos
Message 3 of 13
(5,808 Views)

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

0 Kudos
Message 4 of 13
(5,803 Views)

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

 

 

 

 

 

 

0 Kudos
Message 5 of 13
(5,792 Views)

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

0 Kudos
Message 6 of 13
(5,789 Views)

Hi Simy,

 

This is what I tried but it is not working. What could be the reason for it?

 

Regards,

 

X. Ignatius

0 Kudos
Message 7 of 13
(5,785 Views)

And what is wrong?

Did you get some error?

Simyfren

0 Kudos
Message 8 of 13
(5,783 Views)

Simy,

 

I couldn't find out what was wrong. Attached the error screen for reference.

 

Regards,

X. Ignatius

 

 

0 Kudos
Message 9 of 13
(5,781 Views)

Simy,

 

I couldn't find out what was wrong. Attached the error screen for reference.

 

Regards,

X. Ignatius

 

 

Download All
0 Kudos
Message 10 of 13
(5,781 Views)