Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to read MATLAB's .mat files in Perl?

I have some data generated in MATLAB that I want to process using Perl. I saved the data from MATLAB in a .mat file. Is there any way to read it in Perl?

like image 802
Nathan Fellman Avatar asked Apr 07 '10 16:04

Nathan Fellman


People also ask

How do I view the contents of a .MAT file?

Previewing MAT-File Contents To see what variables are stored in a MAT-file before actually loading the file into your workspace, use whos -file filename . This command returns the name, dimensions, size, and data type of all variables in the specified MAT-file.

Can mat files be opened outside of MATLAB?

. mat files contain binary data, so you will not be able to open them easily with a word processor. There are some options for opening them outside of MATLAB: If all you need to do is look at the files, you could obtain Octave, which is a free, but somewhat slower implementation of MATLAB.

Are .MAT files HDF5?

Version 7.3 MAT-files use an HDF5 based format that requires some overhead storage to describe the contents of the file. For cell arrays, structure arrays, or other containers that can store heterogeneous data types, Version 7.3 MAT-files are sometimes larger than Version 7 MAT-files.

Can Octave Open .MAT files?

mat files that you can download and read directly in any version of Matlab or Octave.


2 Answers

One option would be to save the binary MAT file as ASCII from inside MATLAB using something like:

load('test_data.mat');
save('test_data.asc', 'var1', 'var2', '-ascii');

Then you would have ASCII data to process in Perl.

If you need a solution completely written in Perl, then you should be able to automate the process using the Math::MATLAB package on CPAN.

NOTE: If Python is an option, you could use the loadmat function in the SciPy Python library.

like image 131
Tim Henigan Avatar answered Nov 09 '22 06:11

Tim Henigan


The Java library JMatIO has worked well for me. Maybe you can try using inline Java.

like image 24
weiyin Avatar answered Nov 09 '22 04:11

weiyin