Khalife
Khalife

Reputation: 93

Export Python Arrays to Matlab

I am a beginner with Python and I am encountering the following problem.

I deal with sensors data. Each sensor gives me a np.array with varying size (n,p). For the moment, I just add the new array into a list, and then convert this list in a array, which gives an array of arrays. I would like to export the final result (equivalent to a multi-dimensionnal array with variable size) in a written file that I want to be readable in Matlab to test advanced algorithms on it. My question is the following : is there a better way to collect the data to export it in Matlab? And what could be a possible way to write a Matlab readable file from this multi-dimensional array?

Upvotes: 3

Views: 853

Answers (1)

Iman Mirzadeh
Iman Mirzadeh

Reputation: 13550

Yes there is a better way : use scipy !!
Then you can use savemat method to "Save a dictionary of names and arrays into a MATLAB-style .mat file"
the code would be something like this:

import numpy, scipy.io
your_array = a multi dimential matrix
scipy.io.savemat('your direction and name', mdict={'arr': your_array})

Upvotes: 1

Related Questions