DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use cell value as an index for calculations

Hello,

 

I need to use certain channel values as the index to start and stop calculations (average, max, min).  I already found the row value at which certain times occur using the PNo function so, for example, 2:00:00 AM corresponds to row 721 for all data channels and 4:00:00 AM corresponds to row 1441.  For my Power channel(A) I would like to start and stop calculations between rows 721 and 1441 rather than the entire range of data in the channel.

 

In Excel, I can accomplish this using the INDEX function. To find the average Power between 2 and 4am (time channel B) I would enter into a cell "=AVERAGE(INDEX(A:A,MATCH(VALUE("2:00AM"),B:B,1)):INDEX(A:A,MATCH(VALUE("4:00AM"),B:B,1))). Can I do this in Diadem using Descriptive Statistics in the Analysis panel? I would like to know how to do this manually first before writing any scripts as I am new to Diadem. Thanks!

 

0 Kudos
Message 1 of 4
(5,728 Views)

Hey Sarahg,

 

The easiest way to accomplish this will be to create a new channel for the subset of data, and perform the calculations on that new channel. While there are some ways to create a new channel manually, the easiest way to do this will be with a simple script. I'll paste in the script itself, and then explain it.

 

Option Explicit  'Forces the explicit declaration of all the variables in a script.

Dim firstVal, secondVal, firstIndex, secondIndex

firstIndex = 2
secondIndex = 5

Call DataBlCopy(Ch("Speed"),firstIndex, secondIndex-firstIndex, Ch("Test"),1)

 

Here's what that does:

 

-Define some variables for use later.

-firstIndex and secondIndex are the two indices of interest; in your example, they were 721 and 1441. I just put in numbers for these, but you could easily put a calculation there with the PNo command you mentioned.

-The DataBlCopy actually creates the new channel. The first argument is the channel to copy FROM, so Ch("Speed") is copying from a channel called Speed.

- firstIndex is your first index (721 in your case).

-The next argument is the number of rows to copy. To obtain this value, I did secondIndex-firstIndex. 

-The next argument is the channel to copy TO. So Ch("Test") means we're copying to a channel called Test.

-The last argument is the starting index in that new channel. It will always be 1 (we want to copy starting at the beginning of the channel).

 

 

Once you have the new channel, you can simply use your statistical analysis functions on the new channel. I think this is the easiest way to accomplish the task, and will make it very easy to automate this process later. Please let me know if you have any questions about how to implement it!

-

0 Kudos
Message 2 of 4
(5,703 Views)

Thanks for your reply Daniel. Your code would not work for me as is, I had to add the following code to first create the new channel (as the 3rd channel in the 1st group):

 

CallData.Root.ChannelGroups(1).ChannelsAdd("Test",DataTypeFloat64,3)

Data.Root.ChannelGroups(1).Channels("Test").Name="Test"

 

I was hoping there was a way to execute calculations for subsets of the data without adding more channels as I already have enough to work with. But the end result is the same so thanks for your help!

 

Sarah

0 Kudos
Message 3 of 4
(5,669 Views)

Hi Sara,

 

Daniel's answer is the correct answer in the general case, but for the specific case of the statistics calculations, you CAN specify a row range like this:

 

FOR i = 1 TO 23
  StatSel(i) = "No"
NEXT ' i
StatSel(4) = "Yes" ' Minimum
StatSel(5) = "Yes" ' Maximum
StatSel(6) = "Yes" ' Average
StartRow = 721
StopRow = 1441
Call StatBlockCalc("Channel", StartRow & "-" & StopRow, Channel)
MsgBox StatMin & vbCRLF & StatMax & vbCRLF & StatArithMean

Brad Turpin

DIAdem Product Support Engineer

National Instruments

 

 

Message 4 of 4
(5,637 Views)