04-17-2017 12:32 PM
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.
Solved! Go to Solution.
04-18-2017 09:00 AM
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")
04-19-2017 03:40 AM
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.
04-19-2017 04:43 AM
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.
04-19-2017 07:24 AM
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?
04-19-2017 07:27 AM
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 !
04-19-2017 07:37 AM
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.
04-19-2017 07:53 AM
Oh... I didn't understand you at all 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.
04-19-2017 08:12 AM
oh thank you so much , i will try it !!!