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?
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.
. 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.
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.
mat files that you can download and read directly in any version of Matlab or Octave.
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.
The Java library JMatIO has worked well for me. Maybe you can try using inline Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With