This repository provides a simple and efficient tool for converting MATLAB .mat files into .csv format. It is especially useful for users who want to process or analyze MATLAB data in spreadsheet software or other environments that support .csv files.
- Convert MATLAB
.matfiles to.csv - Supports
.matfiles saved in both v7 and v7.3 formats - Handles multiple variables and structured data
- Easy-to-use command line interface (CLI)
- Minimal dependencies
Given a .mat file with the following structure:
data = struct;
data.temperature = [20.5, 21.0, 21.5];
data.humidity = [30, 35, 40];
save('sensor_data.mat', '-struct', 'data');The tool will generate:
temperature,humidity
20.5,30
21.0,35
21.5,40- Clone the repository:
git clone https://github.com/fazeelibtesam/mat-to-csv.git
cd mat-to-csv- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`- Install dependencies:
pip install -r requirements.txtpython convert.py input_file.mat output_file.csvinput_file.mat: Path to the source.matfileoutput_file.csv: Desired name/path for the output.csvfile
python convert.py data/sensor_data.mat output/sensor_data.csv.matv7 (default format): ✅.matv7.3 (HDF5-based): ✅ (requiresh5py)
- Python 3.7+
scipyh5py(for.matv7.3 support)numpypandas
Install all with:
pip install -r requirements.txt-
Problem:
KeyErrororObject dtype not supported- Solution: Ensure your
.matfile uses arrays and tables, not complex MATLAB objects.
- Solution: Ensure your
-
Problem:
h5pyerror- Solution: Confirm that you're working with a
.matfile saved in v7.3 format.
- Solution: Confirm that you're working with a
If the repo includes tests:
pytest tests/Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.
This project is licensed under the MIT License.
- MATLAB File I/O via
scipy.ioandh5py - CSV processing using
pandas
Feel free to fork, star ⭐, and follow for updates!