DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

script Mean

Solved!
Go to solution

Hello,

i need to have a script that calculate the mean whether the number of channels that i have, attached the script that i wrote , in the script , my channel is ''courbe'', what could i modifie to have something like this : 

call average (" '[1]/courbe' , '[2]/courbe' ,...,/mean.)until the final channel that i have in the Data portal.

0 Kudos
Message 1 of 9
(4,764 Views)

Hello say12,

here the way to do this. Maybe not the best one, but it should work if all your channels are numerical.

If you have not only one channel group, you need to run it in a loop and activate the new group every time, to get the "Mean" right there...

dim list, noChn
'
noChn = Data.Root.ChannelGroups(1).Channels.Count
list = "'[1]/[1]' - '[1]/[" & noChn & "]'"
'
Call ChnAverage(list,"/Mean")

 

0 Kudos
Message 2 of 9
(4,701 Views)

Hello Dia 791

Thank you so much for your answer. However, it seems to me that i did not know exactly how to run it in loop , attached the script that i wrote , what should i modify ? 

Regards.

0 Kudos
Message 3 of 9
(4,683 Views)
Solution
Accepted by topic author say12

Well, the change is rather minor:

dim list, name, noChn, iGroup, noGroup
'
For iGroup = 1 to Data.Root.ChannelGroups.Count                         ' this is a loop over all groups in the NAVIGATOR
  Data.Root.ChannelGroups(iGroup).Activate                              ' set the group as default (activate)
  noChn = Data.Root.ChannelGroups(iGroup).Channels.Count                ' this is the number of the channels in this group
  list = "'[" & iGroup & "]/[1]' - '[" & iGroup & "]/[" & noChn & "]'"  ' create the 'list' for this group
  name = "Mean_" & Data.Root.ChannelGroups(iGroup).Name & "_"           ' here you can adapt the name of the new channel as you like
  Call ChnAverage(list, name)                                           ' create the channel "Mean" inside this group
Next  ' iGroup                                                          ' go to the next group up to the end

I don't really understand, what do you mean with "Piece" and "Matiere" and where do you want to have this info. If in the name of the new generated channel, so just match the "name" content.

 

 

And if you do this for business, I strongly recommend to attend the DIADEM training by NI, it's worth it.

0 Kudos
Message 4 of 9
(4,671 Views)

Hello Dia 791

Thank you for your answer , However, when i run the script , it displays the error : '' object doesn't support this property or method : 'Data.root.channelsgroups in the line 19 (as you can see in the picture attached). do you have any idea why?

0 Kudos
Message 5 of 9
(4,660 Views)

Hello again

and to better understand my problem and  what i mean , as you can see in the attached  script : it allows me to calculate the mean of three test,my problem is that i want to have the same script but that allows to have this mean whatever the number of test i have. i thought to run it in a loop but i did not know how to write it !

 

0 Kudos
Message 6 of 9
(4,656 Views)

To the failure in line 19:

there you assign the content to the string variable moyennes. But you use

Data.Root.ChannelsGroups(iGroup).moyennes

instead of

Data.Root.ChannelGroups(iGroup).Name

This property (moyennes) is not known for DIADEM, therefore the error is raised.

 

Moreover, if you use the variable moyennes for the name of the new channel, please use the same variable in the line 20 (not name, which you don't need any more).

 

The discussion goes more in the area of the programming basics... Sorry, but I guess a course would really help.

0 Kudos
Message 7 of 9
(4,651 Views)

Oh... I didn't understand you at all Smiley Surprised The last picture made it better...

Then the solution provided by Christian should satisfy your needs:

http://forums.ni.com/t5/DIAdem/Script/td-p/3614285

 

There it does not matter how many groups you have, since the channel name (e.g. "force") is the same. And you don't need to create the new group every time, one is enough.

Dim ChnList(3)
'
Set ChnList(1) = Data.GetChannels("*/force")
Set ChnList(2) = Data.GetChannels("*/XYZ")
Set ChnList(3) = Data.GetChannels("*/Energy")
'
Call Data.Root.ChannelGroups.Add("Results").Activate
'
Call ChnAverage(ChnList(1), "/Mean_force")
Call ChnAverage(ChnList(2), "/Mean_XYZ")
Call ChnAverage(ChnList(3), "/Mean_Energy")

For the report, it could be easier to add the curves by drag-and-drop, at least in one report. Then you can see in the curve list, how they are named and what can you change.

 

0 Kudos
Message 8 of 9
(4,642 Views)

oh thank you so much , i will try it !!! 

0 Kudos
Message 9 of 9
(4,636 Views)