LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read labview binary files in Matlab

I would like to read Labview binary files with Matlab. I read some articles of the subject and I am more interesting in know how labview store this data into file. What is the format use by Labview to store this data?
 
Any help is appreciated,
 
Hernando
0 Kudos
Message 1 of 13
(7,118 Views)
LabVIEW stores binary data in whatever manner the programmer chooses. Binary data is pretty generic term. You can store dbl's, sgl's, 8,16,32, 64 bit intergers, and since 8.0, as little or big endian. The number of options is large just as it is in other languages. I think even Matlab gives you a variety of ways to store binary data. You'll need to look at the source code of the LabVIEW program that created the data in the first place unless you want to do a lot of experimentation.
0 Kudos
Message 2 of 13
(7,097 Views)

https://decibel.ni.com/content/docs/DOC-39038

 

In that post I describe my experience with generating binary data in either Labview or Matlab and loading it into either Matlab or Labview.

 

Scope:

1) Write a binary file in matlab and read into labview. 2) Write a binary file in labview and read into matlab.

 

Background:

IMPORTANT:

You must know (3) things about the binary data in the file before you can read the data:

1) what binary format (precision) was used to store the data

2) the exact number of values in the file to read.

3) Endianness There is no row or column in binary files. Think of a long row/or a long column that needs to be mapped to a 2D array.

 

Resources on data in binary format.

 

http://cse.unl.edu/~sincovec/Matlab/Lesson%2024/Binary/CS211%20Lesson%2024%20-%20Binary%20File%20Inp...

0 Kudos
Message 3 of 13
(6,346 Views)

The term "binary file" means that the data on disk is a (pretty close) duplication of the binary format of the data in memory.  For example, a String will appear as an array of Bytes that, if looked at with a text editor, would be "human-readable".  

An I32 or U32 integer would take 4 bytes, but the order (or "Endian setting") can be Big-Endian or Little -Endian (and I won't confuse both of us by trying to say which is which).  Thus the number "1" would appear as four byte of 0, 0, 0, 1 or 1, 0, 0, 0.  Floating point (Dbl) also has an "Endian" consideration, but the numbers are encoded as a mantissa and exponent, with sign appearing somewhere.  However, if you get the Endian and precision (Sgl, Dbl, etc.) right, both MatLab and LabVIEW should be able to read each other's data.

Be careful with Booleans.  It wouldn't hurt to do an experiment and see how many bits/bytes are used for simple Boolean data.

 

One other "gotcha" -- in LabVIEW, you can prepend Array and String writes with a U32 that is the length of the Array/String -- you obviously want to take this into account.

 

Something that I've found helpful when dealing (in both Matlab and LabVIEW) with "unknown" binary data files is to use an old-fashioned "binary editor", something capable of displaying a file as Text and Bytes.  Strings "stand out", and if they seem to be preceded with 4 bytes that are mostly 0 with one Byte more-or-less the length of the String (sign that String Length was prepended).  If you see a lot of byte data that look like they could be 2 or 4 byte integers, they probably are.  If they are four bytes of numeric data that have few zero bytes (i.e. if most of the 32 bits seem to be used), they may well be floats.  Make a guess at the format and write a short routine to read according to your guess -- do you get meaningful data?  Go ahead, be a Scientist, not an Engineer -- study the data, form a hypothesis, then design and do an Experiment and see if you need to reject your hypothesis ...

 

Bob (Neuroscientist) Schor

Message 4 of 13
(6,300 Views)

Hi Manny

 

Does the link you have mentioned about reading matlab binary files in labview exist now. It is not getting redirected.

 

Regards

Rex

0 Kudos
Message 5 of 13
(5,470 Views)

Rex

 

It appears the link that Manny posted is no longer active, but I was able to find another forum post that may be relevant:

 

Loading Labview Binary Data into Matlab
 
 
Let me know if this helps,
Patrick O.
Applications Engineering
National Instruments
0 Kudos
Message 6 of 13
(5,448 Views)

The posts Manny and I made two years ago are still relevant.  There are numerous ways to write the same (binary) data in LabVIEW and have it look different, particularly if arrays and different kinds of numeric data (I32, sgl, dbl, etc.) are involved.  A big help is seeing the LabVIEW code that writes the data, as is actually looking at the data file with a binary editor.

 

Bob Schor

0 Kudos
Message 7 of 13
(5,436 Views)

I haven't played around with it too much, but this Matio library for LabVIEW reads and writes matlab files:

 

https://lavag.org/topic/10976-a-mat-file-io-library/

 

So far all I've done is read some data with it but the API could be better with an OO refactoring.

0 Kudos
Message 8 of 13
(5,412 Views)

you can use the Matlab DataPlugin in labview via storage VIs:

 

http://www.ni.com/example/29178/en/

 

The plugin previous does not support export to Matlab but now it does.  There are some examples of using dataplugin.

 

-Joe

0 Kudos
Message 9 of 13
(5,394 Views)

The matio library is nice, but, ...

it is memory inefficient, lots of strings concatenations, but if you refactor it, it works well. However, the file version in the Matio library is an old Matlab file version which has been superceded. Some limitations of this version are each variable can only have 2^31 bytes in it, Matlab needs to read the whole variable in when loading, that is, Matlab cannot open only a part of the variable, etc.

 

The new Matlab file format is based on HDF, look at the Hierarchical Data Format (HDF5) v2.13.1.143 by Martijn Jasperse on VIPM. It has examples of how to make a Matlab file in a HDF format.

 

mcduff

0 Kudos
Message 10 of 13
(5,389 Views)