LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Loading Labview Binary Files in Matlab

Solved!
Go to solution

Hi,

I'm recording in real time a lot of data at a fast rate with Labview 2018 using the Write to Binary File Function. I wanted to open those files in Matlab to make some analysis on the results but I can't find a post with a clear example.

Thank you.

RMT

0 Kudos
Message 1 of 9
(1,475 Views)

Well, you simply need to know the details (datatype, byte order, size headers, etc.), but you are not providing any. To get specific help, show us how you are writing to file in LabVIEW, maybe even attach a simple example.

 

What is the datatype? Do you write scalars or arrays? LabVIEW is always big-endian so make sure to read it that way in matlab.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 2 of 9
(1,472 Views)

I've added an example. It's badly written but should give the jest of what I'm doing.

 

In this file, I keep generating a 1D integer vector of 512 in length (normally the length is a lot bigger and I'm getting data faster than I can save it on the hard drive)  in one while loop while my second loop is save it to the hard drive.

Datatype: 1D vector integer

No header

 

0 Kudos
Message 3 of 9
(1,451 Views)

I've added a reply with some example code. Is it clearer?

 

Thank you for your help.

0 Kudos
Message 4 of 9
(1,447 Views)

Is this a LabVIEW or Matlab question?

 

You are writing to a flat binary structure in the example you have shown. In Matlab you should use fopen, then fread, and the other elementary commands in Matlab.

 

mcduff

 

 

0 Kudos
Message 5 of 9
(1,430 Views)

@altenbach wrote:

 LabVIEW is always big-endian so make sure to read it that way in matlab.


Last I checked, Matlab defaults to Little Endian.  Luckily, you can set the Endianness with the Write Binary File.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 9
(1,426 Views)

I think I understand how to read the file with Matlab. What I'm missing is how Labview save the files. I understand the median part. What I don't understand is, for each of my saved values in my vector, let's say the first 12, how many bit do I have to read? How many bits in the file correspond to one value?

 

Is it always the same for an integer number in Labview or will it depend on the number itself. Will 12 take as many bits as 1253?

0 Kudos
Message 7 of 9
(1,399 Views)

A sixteen bit number, I16, U16 takes 16 bits, I32, U32, 32 bits, sgl precision 32 bits, double precision 64 bits.

 

Will 12 take as many bits as 1253?

 

The only time these will be different if you were writing ascii characters, each character is 8 bits.

 

mcduff

Message 8 of 9
(1,394 Views)
Solution
Accepted by topic author RaphaelMT

Thank you for your hel, finally understood and I'll post it here for someone else.

 

-The data was saved as u16 which I discored by adding an indicator and looking at the tag on the indicator.

-After that, here is the Matlab code for opening it:

fid = fopen('savedData.dat','r','b'); %r for reading and b for big endian

mydata = fread(fid, 'ubit16', 'b'); %b for big endian again and ubit16 is the format of the data

fclose(fid)

-Then mydata gave me a double precision vector cointaining the same data I had on Labview.

0 Kudos
Message 9 of 9
(1,390 Views)