DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Perform calculations at a segment of a file/samples

Solved!
Go to solution

Hello everyone, 

 

I would like to perform some math calculation at a segment of a tdms file, let's say divide by 1000 only samples index 2000 to 3000 if the total length is 4000. How can you do that?

 

Also I would like to replace with No Value all values less than e.g. 1 (<1). Any ideas?

 

 

Cheers

 

0 Kudos
Message 1 of 6
(4,591 Views)
Solution
Accepted by topic author Saloutios

Hello Saloutios,

 

Almost all analysis function in DIAdem work channel based (the descriptive statistics are an exception), so applying an analysis function to only a segment of a file is not possible without extracting the section from the channel first.

 

My suggestion would be to use the following code:

 

Call ChnLinGen("DivideByChannel",1,1,3000,"") 
Call ChnLinGen("Temp",1000,1000,1000,"") 
Call DataBlInsert("Temp",1,1000,"DivideByChannel",2000)
Call ChnDiv("Data","DivideByChannel","/Divided") 

Line 1 creates a channel called "DivideByChannel" with 3000 values that are all "1".

Line 2 creates a channel called "Temp" with 1000 values that are all "1000".

Line 3 inserts the data from "Temp" into the channel "DivideByChannel" at line number 2000.

Line 4 divides you "Data" channel (with the original data) by the "DivideByChannel" which is now 4000 values long.

 

There are other ways to solve this, but that's the easiest I could think off right now.

 

 

 

Replacing channel values with NoValues based on a condition is relatively easy using the CTNV (Channel To NoValue function of the DIAdem Calculator):

 

Ch("Result") = Ch("[1]/Channel")+ctnv(Ch("[1]/Channel")<1)

 

Just put the above code into the DIAdem Calculator and change the channel name reference to your channel names.

 

The CTNV function returns either a "0" or a "NoValue", and adding these values to the original channel values will create either the original value (channel value + 0 = channel value) or a NoValue (channel value + NoValue = NoValue).

 

 

Otmar D. Foehner
Message 2 of 6
(4,586 Views)

Many thanks Otmar, that will do the trick!

0 Kudos
Message 3 of 6
(4,578 Views)

Hello,

 

I am coming back with an additional question: What Otmar suggested works fine. How can you perform this calculation for a number of channels at once? 

 

I have 14 waveform channels that have recorded currents [mA]. With the calculation Otmar shared i can substitute all current values less than 1mA by using the calculator for each channel. Is there a calculation or script you can have a loop that would do this calculation for all channels? I would like each waveform occuring from each calculation to be stored in a new channel waveform ( 14 waveform channels with current values >=1mA and the No Values).

 

In general it would be useful to see a script that performs an action to a range of channels.

 

Cheers! 

0 Kudos
Message 4 of 6
(4,562 Views)

No ideas? Anyone??

0 Kudos
Message 5 of 6
(4,482 Views)

Hi Saloutios,

 

What part of this is giving you trouble?  If you have a series of VBScript commands that correctly does the analysis for one channel, then performing that same analysis on N channels just requires that you put that code in a loop and execute it N times.  The simplest way to work the channel references is to set up an array variable with N elements, one for each channel you want to loop over, then you can just reference your array variable, say "CalcChannel(i)", inside your looped code.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 6 of 6
(4,183 Views)