Convert MAT to CSV
How to convert MATLAB .mat files to CSV — free methods, no MATLAB license required
Files saved with -v7.3 are HDF5 under the hood — the HDF5 guide pairs with this one. For formats we convert instantly in the browser, see all of our CSV converters.
A .mat file is a saved MATLAB workspace: one or more named variables in a single binary file. One fact decides which tools work on yours: files saved with MATLAB’s -v7.3 flag are secretly HDF5 files and need different tooling than v7.2 and older — if a converter fails with an “unable to read” error, that’s almost always why (see the FAQ). There’s no in-browser converter for this format here yet, so this guide covers the free routes. Fastest with no software: Octave Online below. Python users can jump ahead.
No installation: convert in the browser
Option 1: Octave Online
Octave Online (octave-online.net) is a free browser version of GNU Octave, the MATLAB-compatible environment.
- Open it — Go to octave-online.net and sign in (free — required to upload files).
- Upload your file — Use the file panel on the left to upload your
.matfile. - Run the commands — Paste these into the prompt, one at a time:
load yourfile.mat % replace with your uploaded filename
whos % lists the variables inside
csvwrite("output.csv", A) % replace A with a variable name from whos
- Download the result —
output.csvappears in the file panel; download it from there.
Two honest caveats: csvwrite handles numeric matrices only (for cell arrays or structs, use the Colab option), and Octave cannot load -v7.3 files — if load errors, use the Colab h5py snippet in the Python section below.
Option 2: Google Colab with scipy
- Open Colab — Go to colab.research.google.com, sign in with any Google account, and click New Notebook.
- Upload your file — Click the folder icon in the left sidebar, then the upload button, and select your
.matfile. - Run the code — Paste the snippet below into the cell and press the run button.
- Download the result — Refresh the file sidebar, right-click
output.csv, and choose Download.
from scipy.io import loadmat
import pandas as pd
data = loadmat("yourfile.mat") # replace with your uploaded filename
print([k for k in data if not k.startswith("__")]) # your variable names
df = pd.DataFrame(data["A"]) # replace A with one of the printed names
df.to_csv("output.csv", index=False)
Your uploaded file lives in a temporary private session that disappears when you close the tab — but it is on Google’s servers, so for confidential data use the desktop option below.
Free desktop app: GNU Octave
GNU Octave is a free MATLAB-compatible environment (Windows/macOS/Linux, from octave.org). Like the R case for .rds files, this is an app plus two pasted commands, not a tool you need to learn: install it, then run the same load / whos / csvwrite commands from the Octave Online section. Everything stays on your machine.
Python
scipy.io.loadmat() returns a dictionary of variable names to arrays (plus a few __header__-style keys you can ignore):
# pip install scipy pandas
from scipy.io import loadmat
import pandas as pd
data = loadmat("data.mat")
print([k for k in data if not k.startswith("__")]) # see the variable names
pd.DataFrame(data["A"]).to_csv("output.csv", index=False) # replace A
For -v7.3 files, loadmat raises an error — read them as HDF5 with h5py instead (this is the same task as the HDF5 guide):
# pip install h5py pandas
import h5py
import pandas as pd
with h5py.File("data.mat", "r") as f:
print(list(f.keys())) # variable names
data = f["A"][()] # replace A with one of the printed names
pd.DataFrame(data).to_csv("output.csv", index=False)
One gotcha: MATLAB stores arrays column-major, so v7.3 arrays arrive transposed through h5py — if rows and columns look swapped, use data.T.
R
For v7.2 and older files only, R.matlab::readMat("data.mat") returns a list of the file’s variables — extract the one you want and write.csv() it. The package refuses -v7.3 files; use the h5py route for those.
Which method should I use?
| Your situation | Best method |
|---|---|
| No software installed, one file, data not confidential | Octave Online or Google Colab |
| Confidential data that can’t leave your computer | GNU Octave |
| Many files, or a task you’ll repeat | Python with scipy (h5py for v7.3) |