I'm trying to work with the results of a call to StatBlockCalc to several channels and was hoping to do it efficiently without creating a new channel. The script I'm trying to create would ideally do the following:
I need to call this several times for different subsets of rows (in my case 720 times) such that each subset looks like:
So I'd prefer not to have to create 720 new channels and then delete them or call StatBlockCalc 720 times for each channel.
My current code that just makes new channels (but is slow) looks like:
For iLoop1 = 1 to 720 'sRows is a function of iLoop1 Call StatBlockCalc("Channel", sRows, ChnList) sMeanChn = "[" & iAvgIndex & "]/ArithmeticMean" Set oMeanChn = Data.GetChannel(sMeanChn) 'Do something with oMeanChn Data.Root.ChannelGroups(iAvgIndex).Channels.Remove("ArithmeticMean") Next
I tried using the solution in this post: http://forums.ni.com/t5/forums/v3_1/forumtopicpage/board-id/60/thread-id/10442/page/1, but it seems the only way the ResultStatArithMean property is created is if the rows are set to "1-"
Is there any way that I can avoid creating and deleting 720 channels?
At the bottom of that link you mentioned there is a long list of the global variables populated every time the StatBlockCalc() command is run. You just need to read out the value from, say, the StatArithMean variable and save it to the target array variable you want to fill.
DIAdem Product Support Engineer
I realized I never got back to this and have just been making due with my slow solution up to this point, but I'd really like to speed this up.
I don't think the solution Brad suggested works unless I call the StatBlockCalc command for each channel (right now I only need to call it once per subset of rows for x number of channels).
Quick background on the raw data: I have several channels of data recorded relative to an engine crankshaft encoder. Each channel contains up to 300 engine cycles of data in 0.5 degree resolution (this number could change) and 360 degrees per cycle. What I'm trying to accomplish is getting a single cycle average for each channel. For now lets assume I have 3 channels and each channel contains 3 cycles of data. Ultimately, this is kind of what I'm trying to achieve (unless there is an even faster way:
StatSel(6) = "Yes" ' Arith. mean '------------ Result Storage ------------ StatResChn = 0 'v1g - Changed from 1 to 0 StatResChnNames = 0 StatResChnNameFormat= "NameName" StatClipCopy = 1 'v1g - Changed from 0 to 1 StatClipValue = 0 StatFormat = "" sRows = "" Dim aStats() ReDim aStats(iChnCount) 'Loop through each 0.5 degree of engine cycle, average all 3 cycles for each channel For iLoop1 = 1 to (720) 'Real code has a variable instead of 720 'This creates the subset of rows for each engine cycle position 'In this example it creates a subset for 3 cycles, but in the real code it is 'dynamic and is a function of the total number of cycles sRows = iLoop1 & "," & (720+iLoop1) & "," & (1440+iLoop1) ' When iLoop1 = 1, this averages the 3 cycles for each channel at crank angle position 0.0 degrees ' When iLoop1 = 2, this averages the 3 cycles for each channel at crank angle position 0.5 degrees Call StatBlockCalc("Channel", sRows, "'/HS_P_CYL1' - '/HS_P_CYL3'") 'This next part is what I can't figure out and is non-functioning code 'CycleAvg_HS_P_CYL1(iLoop1) = StatBlockCalc result for channel 1 'CycleAvg_HS_P_CYL2(iLoop1) = StatBlockCalc result for channel 2 'CycleAvg_HS_P_CYL3(iLoop1) = StatBlockCalc result for channel 2 Next 'engine crankshaft position
Based on this example, my current code ends up creating 720 channels of length 3 and subsequently immediately deletes them. (most of my data would result in creatation/deleting channels that are 300 points in length)
I believe Brads solution would require me to have 3*720 total calls to StatBlockCalc (instead of 1*720 calls) but not require creating/deleting channels. (most of my data would require 15*720 or 15*1440 calls to StatBlockCalc)