From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
04-08-2010 12:16 PM
This post explains the Labview binary data format. I couldn't find all of this information in any one place so this ought to help anyone in the future. I didn't want to add any overhead in Labview so I did all of my conversion in Matlab.
The Labview VI "Write to Binary File" writes data to a file in a linear format using Big Endian numbers of the type wired into the "Write to Binary File" VI. The array dimensions are listed before the actual array data.
fid = fopen('BinaryData.bin','r','ieee-be'); % Open the binary file
Dim1 = fread(fid,4); % Reads the first dimension
Dim2 = fread(fid,4); % Reads the second dimension
Dim3 = ...
Each dimension's length is specified by 4 bytes. Each increment of the first, second, third, and fourth byte represent 2^32, 2^16, 2^8, and 1 respectively. 0 0 2 38 equates to 2*256 + 38 = 550 values for that particular dimension.
As long as you know the number of dimensions and precision of your binary data you can load it.
Data = fread(fid,prod([Dim1 Dim2 Dim3]),'double',0,'ieee-be'); % Load double precision data
If you have appended multiple arrays to the same file in Labview you would repeat this procedure. Load each dimension then load the data, repeat.
Data = fread(fid,prod([Dim1 Dim2 Dim3]),'int8',0,'ieee-be'); % Load int8 precision data or boolean data
I had to create a function for my own purposes so I thought I'd share it with everyone else too. I uploaded it to the Matlab File Exchange. The file is named labviewload.m.
This was tested on Matlab R2007a and Labview 8.2.
04-01-2014 10:54 AM
Thanks. I have the same questions as I tried to load labview binary data into Matlab.
-John
08-06-2015 02:54 PM
https://decibel.ni.com/content/docs/DOC-39038
I wanted to add this link to my document on my findings about working with binary data between matlab and labview.
12-28-2015 08:35 AM
Hi 🙂
Happy Holiday season.
I have collceted some data with Labview and I want to open it in MATALB. Because of the special format of my binary file (a 1D array of a cluster of 2 elements), I've been having difficulty reading it in MATLAB.
I have attached a screen shot of my data acquisition process, the collected data (try1) and the VI file that reads the file in Labview. Do you have any suggestions on how to open this in MATLAB?
Please let me know if any more info was needed 🙂
Thanks
Ashkan
12-28-2015 11:50 AM - edited 12-28-2015 12:06 PM
The original Post is more than 5 years old, and is not completely accurate. Here are three Read statements -- the first is the Default (where the left and top terminals are unwired), but the other two are also legitimate ...
The important thing to consider when doing Binary File I/O is that the Reader must know the format used to write the data. There is nothing that requires a LabVIEW User to use the Defaults (in particular, I write packed sample data without the prepended Array Size, which means I need to read them back knowing the size(s) of the Array).
As the Original Poster noted, besides needing to know if the file was written with the default settings for Endian order and whether Size information is present for Arrays and Strings, the Reader also needs to know the exact Type of the Data. LabVIEW data can range from 8-bit to 64-bit integers (both Signed and Unsigned), from 16 to 64-bit Floats, a 128-bit TimeStamp, and Clusters (similar to a Structure in Matlab, along with a few other types like Complex and Variant). If you do know all of this, it isn't difficult to write Matlab code to interpret the (now-known) structure of the data and read it into Matlab.
Indeed, back when I was doing a lot of Matlab programming, I occasionally would get a data tape (tape? just how ancient is this guy?) with records whose format was, shall we kindly say, "inadequately documented". I would read a (tape) record, open it with a Text Editor, and "deduce the Type" by looking for similarities, patterns, and the occasional Ascii string that said "Hi, I'm an Identifier" to me. I'd then write a trial Matlab routine that implemented my "best guess" as to the data structure and plot the data arrays to see if it "made sense" ...
Bob Schor
12-28-2015 12:04 PM - edited 12-28-2015 02:03 PM
(First of all, you should not be appending to an array in an (empty) iniialized shift register. Autoidenxing at the output tunnel would be equivalent and significantly cleaner.)
Yes, matlab is little endian by default, so writing in little endian is a reasonable choice.
Your data structure is a poor choice. It is rather complicated and will have a lot of "decoratations" (i.e. size headers). You will have an initilal I32 giving the size of the cluster array, but then you also have inner size headers, one for each array cluster element. Since all these inner arrays can potentially have different sizes, there will be a lot of parsing required. I would write a few simple files , then verify using a hex editor (or just read it as string and diplsay in hex format). I don't use matlab enough to know the easiest way to parse these structures.
Since you have control over the writing, why can't you pick a more reasonable fomat to begin with? For example, if your inner arrays have a fixed and well known size you could write them as flattenend data, for example.
12-28-2015 03:02 PM - edited 12-28-2015 03:06 PM
@altenbach wrote:
Your data structure is a poor choice. It is rather complicated and will have a lot of "decoratations" (i.e. size headers).
OK, here is a simplified scenario showing the file structure of a similar cluster array (I use I32 inner arrays for simplicity)
Let's start reading the hex formatted file data (everything is little endian, of course):
0400 0000 : The size of the outer cluster array (4, I32, little endian)
0000 0000 : the size of the first array of elment 0 (0, I32, little endian) No element data.
0000 0000 : the size of the second array of elment 0 (0, I32, little endian) No element data.
0100 0000:: the size of the first array of element 1 (1, I32, little endian)
0000 0000: the data of the single element if the first array of element 1.
0100 0000:: the size of the second array of element 1 (1, I32, little endian)
0000 0000: the data of the single element of the second array of element 1.
0200 0000:: the size of the first array of element 2 (2, I32, little endian)
0000 0000 0200 0000: the data of the two elements of the first array of element 2. [0, 2]
0200 0000:: the size of the second array of element 2 (2, I32, little endian)
0000 0000 0100 0000: the data of the two element of the second array of element 2. [0,1]
0300 0000:: the size of the first array of element 2 (2, I32, little endian)
0000 0000 0200 0000 0400 0000: the data of the three elements of the first array of element 3. [0, 2, 4]
0300 0000:: the size of the second array of element 3 (3, I32, little endian)
0000 0000 0100 0000 0200 0000: the data of the two element of the second array of element 2. [0,1,2]
end of file.
You have DBL arrays, so the array data will be 8 bytes (size header is still 4 bytes I32, of course). As you can see, the file structure is relatively ragged. If you set prepend size=FALSE when writing, the first four bytes would be missing.
12-17-2018 03:00 PM - edited 12-17-2018 03:01 PM
https://decibel.ni.com/content/docs/DOC-39038
I wanted to add this link to my document on my findings about working with binary data between matlab and labview.
Is it possible to update this link? When the new NI website came out they blew away all these links.
Thanks
12-17-2018 04:00 PM
Will this discussion help you?
mcduff
02-26-2019 10:21 AM
Hi Dan,
I sent an email to NI Community admins to ask if it was possible to retrieve the information from the link.
If they are unable to retrieve it, I will have to make time to reproduce the example codes.
Regards,
Manny