Python .pickle file to Matlab .mat file converter

Python .pickle file to Matlab .mat file converter

Not all softwares are capable to do all tasks, we need to switch between multiple programming languages or softwares to do our required tasks.

It becomes a hectic job to convert data from one software to another.

The two softwares that are most popular today for research are python and Matlab.

The artificial intelligence and other research frameworks are usually based on python but doing a comparison, graph generation and many other mathematical tasks, Matlab being the still best.

Python language usually saves variables using pickle files and Matlab saves variable information in a .mat file.

We have created a simple python script, that can convert pickle file to Matlab file:

import numpy,
import pickle, sys

if(len(sys.argv) > 2):
	source_name = sys.argv[1]
	dest_name = sys.argv[2]
	a=pickle.load( open( source_name, "rb" ) ), mdict={'pickle_data': a})
	print("Data successfully converted to .mat file with variable name \"pickle_data\"")
	print("Usage: source_name.pickle mat_filename.mat")

Python script can be downloaded from here.



python source_name.pickle mat_filename.mat

The Matlab file will be generated with having data stored in “pickle_data” variable when the file is loaded in Matlab.


Related Links:

One Comment on “Python .pickle file to Matlab .mat file converter”

  1. Hello, where do you plug the usage command? I tried Windows command prompt, anaconda prompt 3, and within Spyder, but none worked even though I made alterations to the command to match the prompt i.e. remove python, put the correct file name within the correct path, etc.

    Could you help with this? Thanks.

Leave a Reply

Your email address will not be published.