LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save matrix

I would like to know how should I save matrix which can have a
different size. I would like to save it in a binary file. How to do it
in LabVIEW 6i?
--
Z pozdrowieniami
Szymon Klause "NightSky"
Bydgoszcz
e-mail: nightsky@box43.pl FidoNet: 2:481/75
0 Kudos
Message 1 of 4
(3,157 Views)
After having opened the file, use the "Write File" function to write the 2D array that you wire on "data" input. Also wire the "header" input to "True". To read data back from file, use "Read File" function wiring a 2D array (may be empty, just the datatype is needed) to the "byte stream type" input. File data comes from the "data" output.

The header input of "Write File" function works like this:
False: variable length data (arrays and strings) are written as individual elements, that means that writing a MxN array writes M*N elements on file, without dimension or length information. Only the content of strings is written.
True: the data is preceded by a header that tells the number of dimension(s) in the array and the size of each dimension. That all
ows to recover on read the binary array along with its size. Strings are preceded with the length on the string so when you call the "Read File" function with a string wired to "byte stream type", a string of the length stored in the header is read.


LabVIEW, C'est LabVIEW

0 Kudos
Message 2 of 4
(3,157 Views)
Jean-Pierre Drolet wrote:

>After having opened the file, use the "Write File" function to write
>the 2D array that you wire on "data" input. Also wire the "header"
[...]
>File" function with a string wired to "byte stream type", a string of
>the length stored in the header is read.

Thank You! It was that what I need.
--
Z pozdrowieniami
Szymon Klause "NightSky"
Bydgoszcz
e-mail: nightsky@box43.pl FidoNet: 2:481/75
0 Kudos
Message 4 of 4
(3,157 Views)
Assuming that your matrix is always 2D array of number and just a different number of rows and columns, one way is to flatten your 2D array to a string and write the string with the Write Characters to File function. To read the data, use Read Characters from File and on the string output, use an Unflatten from String function and wire a 2D array constant to the data type input.

Another way is to first write the number of rows and columns to a file and then write the data using Write to SGL File.vi. Then when you do a read, first read the number of rows and columns and then use those parameters for Read from SGL File.vi. If you are reading a writing DBL's, then make copies of the binary SGL VIs and change the data types.
0 Kudos
Message 3 of 4
(3,157 Views)