Overview
This example demonstrates how to add a 2D array into a TDMS file, where each row of the array belongs to its own channel.
Description
This code uses array manipulation to create each row of a 2D array, and then adds each row to the TDMS file using AppendData. The data from the first row of the array will be added into the first channel, the second row to the second channel, and so on. The section of code that deals explicitly with manipulating and writing out the 2D array to file is included below. It is written in VB.NET using the TDMS libraries that come with Measurement Studio.
Requirements
- Visual Basic with Measurement Studio
Steps to Implement or Execute Code
- Download the attached TDMS write array.zip
- Extract the files
- Open the solution
- Run the program
- Click Create TDMS File
- The TDMS file will be created in the executable directory, which is <TDMS write array>TDMS write array\bin\Debug by default
- View the TDMS file with your favorite viewer. The Measurement Studio example TDMS reader is one option
- Note that each row of the array is in its own column
Additional Information or References
Picture of Code
'write the 2d array to file
Dim i, j As Integer
Dim d1array(2) As Double
For i = 0 To 2 'index through rows
For j = 0 To 2 'index through each element in the row
d1array(j) = dataArray(i, j) 'add the element to a 1d array
Next
myChannel(i).AppendData(Of Double)(d1array) 'add the row as stored in the 1d array into that row's channel
Next
|
**This document has been updated to meet the current required format for the NI Code Exchange.**