Pro Calculators and Guides

What Is Inside a MAT File? Reading MATLAB Data Without MATLAB

The MAT-file versions from level 4 to v7.3, how matrices, structs and cells are stored, and how to browse, plot and export MATLAB data to CSV.

Saizul Amin
Saizul Amin7 Nov 2026 · 4 min read
What Is Inside a MAT File? Reading MATLAB Data Without MATLAB

What Is Inside a MAT File? Reading MATLAB Data Without MATLAB

MATLAB saves workspaces in MAT-files, and those files travel well beyond MATLAB users. Lab instruments export them, course materials include them, and many research datasets are published as .mat files. If you work in Python, R or Excel, or you simply want to see the variable names before writing a loading script, it helps to know what kind of MAT-file you have.

The four versions in practice

  • Level 4 is the original format. It holds only 2-D numeric and text matrices with short names, and it has no text header.
  • Level 5 (v6) starts with a 128-byte header of readable text, followed by tagged elements for each variable. It added multidimensional arrays, cells, structs, objects and integer classes.
  • Level 5 (v7) is the default from MATLAB 7 onwards. It is the same layout, with each variable compressed using zlib.
  • v7.3 is an HDF5 file with MATLAB-specific attributes. It is needed for variables over 2 GB, and the array dimensions appear reversed when you read it as HDF5, because MATLAB stores data column by column.

How MATLAB stores values

Numbers are stored in column-major order: the first column is written top to bottom, then the second column, and so on. Struct fields are stored by name, so a struct called settings with a field gain is easiest to think of as the path settings.gain. A cell array holds any mix of other values, each stored as its own element. Objects such as table, string and datetime are saved in an undocumented internal form, which is why many non-MATLAB readers cannot open them.

Worked example

Open the sample in the MATLAB MAT file viewer. It is a level 5 file called experiment.mat with 4 variables. The Variables tab lists:

NameClassSizeValue
timedouble1×500 to 4.9 in steps of 0.1
signaldouble50×4four signal columns
subjectchar1×15'Trial 12, lab B'
settingsstruct1×13 fields

The settings struct holds rate_hz = 10, gain = [1.5 2 2.5] and operator = 'A. Rahman', and each field appears separately in the dataset list as settings.rate_hz, settings.gain and settings.operator.

Go to Browse arrays and pick signal. The window shows its 50 rows and 4 columns, and the chart draws all four: a sine, a cosine, a sine that fades over time, and a marker column. Row 1 reads 0.0998, 0.995, 0.0966 and 0. Scroll down and you will see the marker equal to 1 on rows 0, 7, 14 and so on up to 49, eight times in all. Press Whole dataset CSV and you get a 50-row grid with a row column and columns 0 to 3, ready for Excel or pandas.

For a 3-D array, such as a stack of images, the browser adds an index box for the first dimension. Each value of that index is one 2-D page, which you page through 200 rows and 40 columns at a time.

v7.3 files

When you open a v7.3 file, the viewer loads h5wasm, the HDF5 library compiled to WebAssembly, from a public CDN the first time, so an internet connection is needed once. The file is read on your device. The Variables tab reverses the HDF5 sizes back into MATLAB order, while the array browser shows the stored, transposed shape. A 3×1000 matrix in MATLAB will therefore appear there as 1000 rows by 3 columns.

Common mistakes

Reading a v7.3 file as level 5. Tools such as scipy.io.loadmat cannot read v7.3 files and raise an error. If that happens, read the file with an HDF5 library such as h5py instead, and remember to transpose the arrays.

Losing orientation. A 1×50 row vector and a 50×1 column vector hold the same numbers but export with different shapes. Check the size column before you reshape anything.

Expecting tables and strings to open. Variables of class table, string, datetime or categorical are listed but not decoded. Convert them in MATLAB first, for example with table2array or cellstr, then save again.

Exporting a huge array in one go. The whole-array CSV is limited to 5 million values. Larger arrays can be exported as slices, or read directly with a script.

After exporting

The viewer is a quick way to check names, shapes and values. It is a data view rather than engineering or scientific advice, so if a result depends on an exact value, confirm it in MATLAB or in the software that produced the file.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages