Skip to content

fazeelibtesam/Conversion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

.MAT to .CSV Converter

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.


🚀 Features

  • Convert MATLAB .mat files to .csv
  • Supports .mat files saved in both v7 and v7.3 formats
  • Handles multiple variables and structured data
  • Easy-to-use command line interface (CLI)
  • Minimal dependencies

📁 Example

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

🛠 Installation

  1. Clone the repository:
git clone https://github.com/fazeelibtesam/mat-to-csv.git
cd mat-to-csv
  1. Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  1. Install dependencies:
pip install -r requirements.txt

📦 Usage

Command Line

python convert.py input_file.mat output_file.csv

Options

  • input_file.mat: Path to the source .mat file
  • output_file.csv: Desired name/path for the output .csv file

Example

python convert.py data/sensor_data.mat output/sensor_data.csv

🧩 Supported File Types

  • .mat v7 (default format): ✅
  • .mat v7.3 (HDF5-based): ✅ (requires h5py)

📚 Requirements

  • Python 3.7+
  • scipy
  • h5py (for .mat v7.3 support)
  • numpy
  • pandas

Install all with:

pip install -r requirements.txt

🔍 Troubleshooting

  • Problem: KeyError or Object dtype not supported

    • Solution: Ensure your .mat file uses arrays and tables, not complex MATLAB objects.
  • Problem: h5py error

    • Solution: Confirm that you're working with a .mat file saved in v7.3 format.

🧪 Tests

If the repo includes tests:

pytest tests/

🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.


📄 License

This project is licensed under the MIT License.


🙋‍♂️ Acknowledgments

  • MATLAB File I/O via scipy.io and h5py
  • CSV processing using pandas

Feel free to fork, star ⭐, and follow for updates!


About

Python script to convert .mat file to .csv

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors