10-31-2006 03:30 PM
11-01-2006 02:42 PM
08-06-2015 03:08 PM
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.
08-08-2015 12:57 PM
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
09-29-2017 02:37 AM
Hi Manny
Does the link you have mentioned about reading matlab binary files in labview exist now. It is not getting redirected.
Regards
Rex
10-02-2017 09:21 AM - edited 10-02-2017 09:22 AM
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:
10-02-2017 03:31 PM
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
10-03-2017 12:44 PM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
10-04-2017 11:10 AM
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
10-04-2017 11:28 AM
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