Search code examples
perlmatlabfile-iomat-file

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?


Solution

  • 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.