Questions tagged [mat-file]

Use with questions about .mat files. These files are used for storing MATLAB variables.

MAT-file is binary file format, used to store data in multiple variables or structures in MATLAB. These files use the .mat extension, and can be accessed in using the load, save or matfile functions. For more information, see MAT-File Versions in the MATLAB documentation.

MAT-files can be also created and read by other programming languages such as Python etc.

Refer to this PDF document for a description of the internals of the MAT-file format (Level 4 and Level 5).

218 questions
558
votes
16 answers

Read .mat files in Python

Is it possible to read binary MATLAB .mat files in Python? I've seen that SciPy has alleged support for reading .mat files, but I'm unsuccessful with it. I installed SciPy version 0.7.0, and I can't find the loadmat() method.
Gilad Naor
  • 20,752
  • 14
  • 46
  • 53
102
votes
10 answers

reading v 7.3 mat file in python

I am trying to read a matlab file with the following code import scipy.io mat = scipy.io.loadmat('test.mat') and it gives me the following error raise NotImplementedError('Please use HDF reader for matlab v7.3 files') NotImplementedError: Please…
Shan
  • 18,563
  • 39
  • 97
  • 132
26
votes
2 answers

How do you open .mat files in Octave?

I have a .mat file that I want to open and see its contents. Since I don't have MATLAB, I downloaded GNU's Octave. I'm working on Mac's terminal so I'm not exactly sure how to open the .mat file to see its contents. How to do this?
user1257724
26
votes
1 answer

MATLAB: Differences between .mat versions

The official documentation states the following: . But I have noticed that there are other important differences besides those stated in the table above. For example, saving a cell array with about 6,000 elements that occupies 176 MB of memory in…
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
20
votes
1 answer

Access .mat file containing matlab classes in python

I have a .mat file generated from matlab 2012b. It contains a variable with a user-defined matlab class. When loading the file using scipy.io.loadmat in python 3.3, I get the following: mat=scipy.io.loadmat('D:\test.mat') mat {'__header__': b'MATLAB…
PaulD
  • 615
  • 1
  • 8
  • 15
17
votes
2 answers

Access array contents from a .mat file loaded using Scipy.io.loadmat - python

UPDATE: This is a long question that boils down to, can someone explain the numpy array class to me? I answered my own question below. I am working on a project to import data from matlab into a mysql database whose contents will be made available…
sequoia
  • 3,025
  • 8
  • 33
  • 41
16
votes
4 answers

deleting variables from a .mat file

Does anyone here know how to delete a variable from a matlab file? I know that you can add variables to an existing matlab file using the save -append method, but there's no documentation on how to delete variables from the file. Before someone…
eykanal
  • 26,437
  • 19
  • 82
  • 113
15
votes
1 answer

Importing an array from matlab into R

I'm sure this is a simple problem, but I haven't been able to find an obvious solution. I have a series of model output array files (dim 180, 360, 12) generated in matlab that I need to open in R. I have attempted to use the R.matlab package, simply…
Clive Trueman
  • 151
  • 1
  • 1
  • 3
14
votes
7 answers

Find all differences between .mat files

I am looking for a way to list the differences between two .mat files, something that can be usefull for many people. Though I searched everywhere I could think of, I have not found anything that meets my requirements: Pick 2 mat files Find the…
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
13
votes
2 answers

How can I check the contents of a MAT-file in MATLAB without loading it?

I have a large structure in a MAT-file. I want to check if a specific field is present in the structure without loading the MAT-file since the contents are very large and I want to minimize memory use. Is this possible, or must I load it first like…
Elpezmuerto
  • 5,391
  • 20
  • 65
  • 79
13
votes
2 answers

Python to MATLAB: exporting list of strings using scipy.io

I am trying to export a list of text strings from Python to MATLAB using scipy.io. I would like to use scipy.io because my desired .mat file should include both numerical matrices (which I learned to do here) and text cell arrays. I tried: import…
wwwilliam
  • 9,142
  • 8
  • 30
  • 33
12
votes
4 answers

How to preserve matlab struct when accessing in python?

I have a mat-file that I accessed using from scipy import io mat = io.loadmat('example.mat') From matlab, example.mat contains the following struct >> load example.mat >> data1 data1 = LAT: [53x1 double] LON:…
mikeP
  • 801
  • 2
  • 11
  • 20
11
votes
7 answers

Turn the dictionary keys into variable names with same values in Python from .mat Matlab files using scipy.io.loadmat

I am trying to take a basic dictionary temp = {'key':array([1,2])} loaded from a .mat file with scipy.io.loadmat. Turn the keys in the Python dictionary file returned by loadmat() into variable names with values the same as the representing keys. So…
J Spen
  • 2,614
  • 4
  • 26
  • 41
11
votes
3 answers

MATLAB: Saving several variables to "-v7.3" (HDF5) .mat-files seems to be faster when using the "-append" flag. How come?

NOTE: This question deals with an issue observed back in 2011 with an old MATLAB version (R2009a). As per the update below from July 2016, the issue/bug in MATLAB seems to no longer exist (tested with R2016a; scroll down to end of question to see…
Ole Thomsen Buus
  • 1,333
  • 1
  • 9
  • 24
10
votes
2 answers

Saving and loading Python dict with savemat results in error

Here is an minimal example of the error I get. If I understood the documentation correctly, this should be working, but it seems I did not. a={} a['test1']=1 a['test2']=2 a['test3']=3 import scipy.io as io io.savemat('temp',{'a':a}) b =…
Framester
  • 33,341
  • 51
  • 130
  • 192
1
2 3
14 15