11-27-2018 03:39 PM
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
Solved! Go to Solution.
11-27-2018 03:52 PM - edited 11-27-2018 03:55 PM
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.
11-27-2018 04:40 PM
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
11-27-2018 04:41 PM
I've added a reply with some example code. Is it clearer?
Thank you for your help.
11-27-2018 06:42 PM
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
11-27-2018 06:56 PM
@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.
11-28-2018 09:48 AM
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?
11-28-2018 09:56 AM
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
11-28-2018 10:14 AM
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.