I am building a software and a part of this software needs to read a .mat file and give the content to a matlab function as argument. The problem is that I have bad data structure I guess.
In fact my Matlab structure called handles
doesn't have the same data structure than my handles
in my Python (after conversion)
When I load the .mat file from python with scipy.io.loadmat()
, I have those 4 keys:
So in handles.simulation
there supposed to be this content:
So I use matlab.engine
to call matlab function in my case the function is called VS_Parametrise
and when I pass my handles
which is a dict:
# -*- coding: utf-8 -*-
import sys
import os
import Tkinter
import numpy as np
from tkFileDialog import askopenfilename
from structDataConfFile import structConfFile
try:
import matlab.engine
except:
print "No matlabEngine installed"
print "Running installation procedure..."
print " "
import installMatlabEngine
print " "
print "Application will exit now..."
print "Please re-run this program to continue installation!"
print " "
exit()
# Environment PATH
Mlab = os.environ.get("MATLAB")
vssFolderPath=os.environ.get("CONTIAME")+'/4_Tools/Veh_Sim_Suite/VSimu'
ContimodelPath=os.environ.get("CONTIAME")
FILETYPES = [ ("text files", "*.mat") ]
handles = dict()
def selectConfFile():
""" Return the path of .mat file
Function that open files browser to choose a .mat file and build handles
dictionary.
"""
Tkinter.Tk().withdraw() # Close the root window
in_path = askopenfilename(filetypes=FILETYPES)
if len(in_path) == 0:
handles['Simulation'] = list()
elif len(in_path) > 0:
handles['Simulation'] = structConfFile(in_path) # HERE I FILL SIMULATION
handles['contimodel_path'] = ContimodelPath
return in_path
def Parametrize(confFile):
""" Return
Argument:
confFile -- str() Configuration File path
Function that call MatLab function passing handles structure/dict as
argument. The return value of MatLab function called VS_Parametrize(handles)
is the modified handles structure.
"""
eng = matlab.engine.start_matlab()
eng.addpath(vssFolderPath)
eng.VS_Parametrise(handles) ############# HERE I CALL VS_PARAMETRIZE
In my matlab function handles.simulation
there are structure of structure of structure.
In Python it should be dictionary of dictionary of dictionary but I get this error:
And I don't understand why when i load the file in Python the first floor of the data structure is a dict and the second is a numpy.ndarray (1st floor: simulation, 2nd floor: parameter/info). Here is more documentation about Matlab to Python variable
Any idea ?