tags:

views:

224

answers:

2

Hi all, I have a variable exon = [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10]]]. I would like to create a mat file like the following

>>

exon : [3*2 double] [2*2 double]

When I used the python code to do the same it is showing error message. here is my python code

import scipy.io
exon  = [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10]]]
scipy.io.savemat('/tmp/out.mat', mdict={'exon': (exon[0], exon[1])})

It will be great anyone can give a suggestion for the same. thanks in advance Vipin T S

+1  A: 

Sage is an open source mathematics software which aims at bundling together the python syntax and the python interpreter with other tools like Matlab, Octave, Mathematica, etc...

Maybe you want to have a look at it:

dalloliogm
A: 

You seem to want two different arrays linked to same variable name in Matlab. That is not possible. In MATLAB you can have cell arrays, or structs, which contain other arrays, but you cannot have just a tuple of arrays assigned to a single variable (which is what you have in mdict={'exon': (exon[0], exon[1])) - there is no concept of a tuple in Matlab.

You will also need to make your objects numpy arrays:

import numpy as np
exon = [ np.array([[1, 2], [3, 4], [5, 6]]), np.array([[7, 8], [9, 10]]) ]

There is scipy documentation here with details of how to save different Matlab types, but assuming you want cell array:

obj_arr = np.zeros((2,), dtype=np.object)
obj_arr[0] = exon[0]
obj_arr[1] = exon[1]
scipy.io.savemat('/tmp/out.mat', mdict={'exon': obj_arr}

or possibly (untested):

obj_arr = np.array(exon, dtype=np.object)
thrope