LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to read a Matlab MAT file into labview.

I do not have Matlab.  I have a series of *.mat files that are created by another program that I want to read into LabVIEW.  The *.mat files should contain a very long 2 dimensional array of complex numbers, with only 2 columns.  I am hoping that the *.mat format is straight forward.  I need to read this into a LabVIEW array to manipulate it.
 
Has this been done?  I've found several routines that allow you to save data from LabVIEW into a *.mat file so that Matlab can read it, but I have not seen anything that goes in my direction.  Any help is appreciated.
 
Mike
Message 1 of 9
(21,437 Views)

Hi Mike,

Since the MATLAB(R) binary format is different from that of LabVIEW, I don't think that there is any way to import the binary MATLAB files into LabVIEW.  However, LabVIEW can read MATLAB files saved in ASCII format with a tab delimiter.  You could use the Read Spreadsheet VI to return these MATLAB files in arrays.  For more information, check out this Knowledgeable: Can I Import Data from the MATLAB development environment to LabVIEW or Vice Versa?

Best Regards,
Megan B.
National Instruments

0 Kudos
Message 2 of 9
(21,417 Views)
I was bored so I decided to tackle this one...Smiley Very Happy

Since the poster indicated he did not have Matlab he wouldn't be able to save the file in ASCII format... I put together a crude VI that should be able to work for you. The MAT file structure is pretty complicated since there are so many datatypes, so I concentrated on being able to read MAT files that were two-dimensional arrays of complex numbers. Try it and see if it works for you. It seemed to work with the 2D arrays of complex numbers that I created in Matlab.

The programming is a bit sloppy so you should clean it up a bit.
Message 3 of 9
(21,414 Views)

Thank you for your efforts.  I should have mentioned that the file appears to be saved in Matlab 4 format.  I think what you wrote is expecting a matlab 5 format.

If you still have some time, maybe you can modify your program to read matlab 4 files.

I tried attaching a sample file several times now, and my reply does not seem to make it onto the thread.  Maybe my sample file is too large.  So I am submitting this response without the sample.  I will try to generate a smaller file and submit it as well.

Mike

0 Kudos
Message 4 of 9
(21,398 Views)
Here is a smaller version of the files that I am trying to read.
 
The save dialog box indicates that this is a file type:  MAT-File (Version 4)(*.mat)
 
Hope this helps.
 
Mike
0 Kudos
Message 5 of 9
(21,391 Views)
Oh, yeah, that certainly makes a big difference.

You're even luckier that I was still bored, so I whipped something together. Smiley Very Happy

See attached.

Couple of things:
(1) I couldn't test it for all data types so the "Parse Data" VI may need to be tweaked for some of the data types.
(2) Your file contained multiple variables and the one matrix of complex values was a 1D array so you may need to insert a "Transpose 2D Array" function where the bundle function is for your 2D array.
(3) A couple of the variables were character arrays but Matlab stores the individual characters as floating point numbers between 0 and 255 representing ASCII-encoded characters. These are the "XUnit" and "YUnit" arrays.

For your reference, the MAT file format is at http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf

Oh, I think I may have left breakpoints in when I saved the VI. Sorry about that. You should remove them when you run the VI so they don't become annoying.

Message Edited by smercurio_fc on 02-09-2006 05:07 PM

Message 6 of 9
(21,388 Views)
I have tried this out, and it looks like it will work for me.  Thank you for the help.
 
Mike
0 Kudos
Message 7 of 9
(21,362 Views)

Hi smercurio_fc,i am trying to do a similar thing you have helped mike with here.Sorry for reposting here i can see this post was in 2006.I have a one tank system in simulink and i have been able to save the output as an array in a Mat-file.Now i want to read and display this output in labview as i am using labview as the user interface of the simulink tank system.Do you think the vi you did for mike can work for me or are you still bored :).Please find attached the labview vi i will like to incorporate with the vi you have done here.Thanks

0 Kudos
Message 8 of 9
(17,415 Views)

There is a DataPlugin for LabVIEW that allows you to read and write .mat files.

 

Check out more about using DataPlugins in LabVIEW here: http://zone.ni.com/devzone/cda/tut/p/id/11951

Chris
Certified LabVIEW Architect
Certified TestStand Architect
Message 9 of 9
(17,398 Views)