11-10-2020 07:31 AM
Hi,
I regularly use a few lines of code that calculate the average of some points of data in the following way:
Set ChnResult = ChnStatisticsChannelCalc(YRChn, 32, L2, L3, , True)
YRss = ChnResult.Item(1).Values(1)
Call Data.Root.ChannelGroups(1).Channels.Remove("ArithmeticMean")
But I am now finding I need to use the code when there are multiple groups in the data file and I might not know which group is the default. This poses a couple of questions:
1. Can I control where the result of ChnStatisticsChannelCalc is placed?
2. Can I delete a channel by knowing only its name and not which group it's in?
The answer to the first question might make the second question obsolete but it would still be good information. The answer to the second question would always be useful to know. Effectively, I would like to put an * in the ChannelGroups index.
Thanks, Simon.
Solved! Go to Solution.
11-10-2020 12:56 PM
Following code would help you
Option Explicit
' load some data
data.Root.Clear
DataFileLoad ProgramDrv & "Libr\Data\Example.tdm", "TDM"
dim YRChn : set YRChn = Data.Root.ChannelGroups(1).Channels("Geschwindigkeit")
' new channels will be generated in the active group
data.Root.ChannelGroups(1).Activate
' calculate statistics
Set ChnResult = ChnStatisticsChannelCalc(YRChn, 32, 1, 10, , True)
' extract content
dim YRss : YRss = ChnResult.Item(1).Values(1)
' delete the channels
dim tempChannel : for each tempChannel in ChnResult
dim grpO : set grpO = tempChannel.ChannelGroup
grpO.Channels.Remove(tempChannel.name)
Next
11-11-2020 03:36 AM
Thanks Andreas.
For the moment I have gone with:
Set ChnsToDel = Data.GetChannels("*ArithmeticMean*")
Call Data.Remove(ChnsToDel)
...because I'm only calculating one statistic at a time.
I will mark your reponse as the solution though.
I assume it isn't possible to directly control where the result of ChnStatisticsChannelCalc is placed within the function call itself. The only way being to set the default group prior to the calculation?
It would be an even better function if you had the option to just take the answer and not create the channel. I rarely need the channel so it's almost always deleted in the following line of code!
Regards.
11-18-2020 12:00 PM
A couple of items:
Option Explicit
' load some data
data.Root.Clear
DataFileLoad ProgramDrv & "Libr\Data\Example.tdm", "TDM"
dim YRChn : set YRChn = Data.Root.ChannelGroups(1).Channels("Geschwindigkeit")
' calculate statistics
Set ChnResult = ChnStatisticsChannelCalc(YRChn, eStatsArithmeticMean, 1, 10) 'For clarity, using eStatsArithmeticMean rather than "32" and leaving off the "True"
' extract content
dim YRss : YRss = StatsResult(eStatsArithmeticMean) 'Reference the stat result directly
11-19-2020 02:15 AM
Thank you for this update. In particular because I tried to get my code to work without generating the result channel and couldn't. I don't need the channel in 99% of cases so this is a welcome improvement. I can't work out why my original attempt at it didn't work; that's lost in time.
Regards.
11-30-2020 08:39 AM
Hi,
I've come across a need to check whether a channel exists before setting an object variable to represent it. I think the code you offer above will fail because if the channel "*/ArithmeticMean*" does not exist then the Set statement will cause an error.
I will post separately to ask for neat ways to make the check first, before using the Set statement.
Regards, Simon.