From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you find the average value of all the data between two points on a single channel

Solved!
Go to solution

I am tring to calculate the average value of all the data points on a single plot between two seperate points

 

I have attahced an illustration.

 

 

Tim
0 Kudos
Message 1 of 16
(10,239 Views)

Hi smoothdurban,

 

There are several ways to tackle this.  Ultimately you'll always be calling the StatBlockCalc() function and specifying the row subset of interest to return the average values in that row range.  The question is how to determine the row range from the cursor range.  This isn't hard, but it isn't obvious either.  Here's a full-blown example that recalculates the statistics each time you move the cursor.  There's also a shipping example that does something similar.

 

Let me know if you need more help,

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 2 of 16
(10,217 Views)

Hey Brad,

 

Thanks for the prompt reply.  I keep getting the attached error.

 

Once the script is running properly I would imagine I would pick the points I would want to evaluate?

 

Where isthe output displayed???

Tim
0 Kudos
Message 3 of 16
(10,214 Views)

Hey smoothdurban,

 

I've seen Brad's code, and trust me, it's worth the effort to let him help you get it up and running - it's definitely the most ideal way to solve this problem.  However, as Brad said, there are multiple ways to tackle this - both interactive and programmatic - so in the meantime, I'll take a second to detail one of the interactive and sure-fire ways to find the average of data between two points on a single channel.

 

We'll use"Flags."  Set up your VIEW graph exactly as you did on your original screenshot, using Band Cursors to approximate the beginning and ending X-values representing the range you want to examine.  Next:

 

1. Click the "Set Flags" button (Button.png) that is a part of your 2D Axis System.  Note that you can hold down the Shift button if you ever decide you want to do this on more than a single curve at one time.


Set Flags.png

2. Select the "Flags: Copy Data Points" button that enables after Flags are set.

 

Copy Data Points.png

3. This creates new channel(s) in the default (bold) group in the Data Portal that contains only the Flagged data.

4. Select DIAdem ANALYSIS.

5. Select Statistics » Descriptive Statistics.

6. In the Channels input, select the newly created channel containing your Flagged Y-Data.

7. Ensure that the Arithmetic Mean parameter is set.  You can preview the data and the result in the dialog before pressing OK to execute the calculation. 

 

You may have noticed that in the Descriptive Statistics calculation, one of the parameters that you can set is the range of channel rows to operate on - so, if you know the row numbers of your beginning and ending X-values, you could just simply run the Descriptive Statistics calculation and use this parameter to operate on a row subset of your original channel instead of the entire channel.

Derrick S.
Product Manager
NI DIAdem
National Instruments
Message 4 of 16
(10,207 Views)

Hi,

 

Somebody correct me if I am wrong on this, but to get Brads scripts to work all you have to do is copy all the files in his zip archive to a folder of your choice and just run the "Stat Range.VBS" script. If you say load in the data in the example by hand and also open the layout file provided by hand then I can imagine you would get the error you are mentioning.

 

If you want it to work with your own data, you'll need to copy your TDM/TDX files to the directory where you have stored the scripts, create your own layout files for your data and edit lines 3/4 of "Stat Range.VBS" accordingly

 

Regards

 

Matthew

0 Kudos
Message 5 of 16
(10,184 Views)

Hi smoothdurban,

 

That sounds like the VIEW cursor event function didn't get declared.  Did you detach all 5 files in the ZIP to the same folder?  Did you run the "Stat Range.vbs" file in DIAdem-SCRIPT?  This should load up a sample data set and a custom VIEW template.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 6 of 16
(10,172 Views)

I was able to get the script file to work.  I guess my next step would be how would I locate the first instance occurrence of a value in one graph, record the row number then find the first occurrence of a second graph record the row number then have these row numbers plugged into the Descriptive statistics to find the mean and the difference of time between these points?

Tim
0 Kudos
Message 7 of 16
(10,166 Views)
Solution
Accepted by topic author smoothdurban

Hi smoothdurban,

 

I thought you wanted to specify the region of interest with the band cursors.  If you instead want to automatically define the region of interest based on threshholds, etc., then we don't need the interactive nature of the example I sent.

 

What are the criteria to use to determine the starting and ending rows of the region of interest?

 

I'd be able to bang this out for you if you sent me a representative data set (brad.turpin@ni.com)

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 8 of 16
(10,159 Views)

Hello,

 

I need exactly same solution that You showed here, but it does not work correctly in my computer (Diadem 2015 15.0.0f6005 (64-bit) version).

Script works, but there's an error with displaying values, instead of Max/Min/Average I receive a message: "@@Str(ChnPropValGet(" & Ych & ", ""ResultStatMax""),       ""AutoAdj"")).

 

It looks that there's an issue with reference to those properties, because when I commented Max/min/average other values of Xmin and Xmax are displayed correctly (and they are changing dynamically when I move cursors).

 

I did not modify Your scripts - just unzip them and run.

 

Could You please help me to understand what is the issue here ?

 

Thank You in advance for help.

 


 

 

0 Kudos
Message 9 of 16
(6,681 Views)

Hi All,

 

It looks like at some point the StatBlockCalc() command stopped automatically writing result properties when it is configured to calculate over a small row range (not the whole channel).  Here's an updated event script that writes those properties explicitly so that it works again in modern DIAdem versions.

 

Thanks for the nudge,

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 10 of 16
(6,642 Views)