LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I read labview 7.1 binary data into matlab 6.5?

I hope that i ask the question in the correct forum that time. I have recorded important data with Labview 7.1 in a binary format, and i would like to import them into matlab 6.5 to further work on them. But I don't know how to write the correct code under matlab. Thanks in advance for your help,
J-F L
0 Kudos
Message 1 of 14
(5,310 Views)
Hello JFL,

my 2 cents:
1) Probably you should ask in a MatLab-forum...
2) It would be very helpful if you could explain your binary format. Is it integer or floating point? Which type of them? Are the data items all of the same type or have you mixed them? Are there any information header in the file? And so on...

Best regards,
GerdW
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 14
(5,301 Views)
Hi
A look at this link coul help.
http://erdos.math.unb.ca/~knight/matlab/inout1.htm
In matlab, you can read binary files if you know the original labview data typer (i8,i16.dbl, etc)
I think Labview if Bigendian and Matlab Little, so bear that in mind to read labview files using matlab.

Cheers
Alipio
---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
Message 3 of 14
(5,297 Views)
Thanks for the responses.
1) the format of my data under labview is 'double', and I just have this type of data (no header, etc...)
2) So far, I did not manage to find a way to convert these binary data (stored under Labview as Bigendian) into a readable format for matlab (which apparently need Littleendian format).
Is such a conversion possible?

JFL
0 Kudos
Message 4 of 14
(5,276 Views)
Well, the matlab function to do that read is fread
See this link:http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fread.html
Look at NI data format types and see what matlab machine format fits the Labview DBL.
In matlab or "googling" you will find examples or matlab scripts to read your data.
Cheers
Alipio
---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
Message 5 of 14
(5,265 Views)
Maybe a related problem:
I have been storing 1.5 Megapixel images in binary format using Labview. Something strange happens however when I try to read these files into Matlab (6.1) of Mathematica (4): at some points entire bytes vanish from the data, essentially shifting the subsequent bytes forward. Only 234B of 2,8MB have disappeared, but that's enough to ruin the picture, of course.
As we tried 2 different math-programs to read the files and they both show the same defects in the data-set I think it has something to do with the way LabVIEW stores the files. LabVIEW itself however reads the data back correctly.

So before I start building an procedure to correct these defects, I figured I'd try this place. Anyone any clue on this?

Thanks in advance,

RS
0 Kudos
Message 6 of 14
(5,200 Views)
Rick,

I personally need more information about the file format before I can hazard any guesses as to the problem. How many bytes per pixel? Is there header information included in the file?

My personal troubleshooting technique would probably be to create a much test image file (say, one for a 10x10 image in the same format) and try to read that into MATLAB or Mathematica. The advantage here is that the file is small enough that you can examine each byte and determine where the disconnect is between the file structure and what the software is expecting.

The biggest gotcha that you're almost certain to be facing is the little-endian/big-endian issue, where LabVIEW writes the data in big-endian format and the other programs may expect the opposite. There's much more about that issue in these forums and elsewhere.

Regards,
John
0 Kudos
Message 7 of 14
(5,175 Views)
Dear John,

Thanks for the suggestion... I actually cracked the problem late yesterday afternoon.
The little and big endian thing was okay, and the actual problem was sillier than that: After recording the pictures I copied them from the measurement computer onto a server through FTP. I used this copy for analysis. However, in transmission some (random) bytes were lost.
We actually wrote a correction procedure which set the lost pixels to 0. When we transferred this procedure back to the measurement set-up to test it on the original image, and displayed the image, the (black) bad pixels were gone. Sure enough, the original files were 234B larger than the copies on the server. Pretty stupid action on my side, I guess :S.

Rick
0 Kudos
Message 8 of 14
(5,168 Views)
using "fread" function in matlab can help .
 
fid=fopen('filename.bin', 'r');
A=fread (fid);
plot (A);
 
for use A=A' then plot u will see the data.
ok
Haider
0 Kudos
Message 9 of 14
(4,842 Views)
I am writing binary data as attached in writeBin.vi

Then I use the following Matlab code to read the binary data to Matlab:

fid = fopen('c:\temp\data.bin','r');
data=fread(fid,'double','b')
cl=fclose(fid);

But it reads senseless data. I write data in Big-endian order in LV and I follow this in Matlab so can somebody tell me where is the problem?

If I write double 0-9 it reads in Matlab
data =
2.122e-313
5.2998e-315
5.305e-315
5.3076e-315
5.3102e-315
5.3115e-315
5.3128e-315
5.3141e-315
5.3154e-315
5.316e-315

I know that it is not strictly LabView question but I appreciate any help
Thanks

Message Edited by ceties on 05-22-2007 10:01 AM

LV 2011, Win7
0 Kudos
Message 10 of 14
(4,661 Views)