itom

8.6. Python-Module matlab

«  8.5. Python-Module matplotlib   ::   Contents   ::   8.7. Reload modified modules  »

8.6. Python-Module matlab

itom provides the python module matlab that can be used to establish a remote control to the Matlab software. Using this module, the following features are available:

In order to use this matlab module, the following requirements have to be fulfilled:

The following example is also included in the demo folder (demoMatlabEngine.py) and shows how to remotely control Matlab via itom:

try:
    import matlab
except Exception as ex:
    print("itom is possibly compiled without Matlab support. This demo is not working")
    raise ex

session = matlab.MatlabSession() #a Matlab console is opened

session.setString("myString", "test") #creates the string variable 'myString' in the Matlab workspace with the value 'test'
print("myString:", session.getString("myString")) #returns 'test' as answer in itom
session.setValue("myArray", dataObject.randN([2,3],'int16')) #creates a 2x3 random matrix in Matlab (name: myArray)
arr = session.getValue("myArray") #returns the 2x3 array 'myArray' from Matlab as Numpy array
print(arr)

#read the current working directory of matlab
session.run("curDir = cd")
print(session.getString("curDir"))

#run directly executes the command (as string). This is the same than typing this command into the command line of Matlab.
#use this to also execute functions in Matlab. At first, send all required variables to the Matlab workspace, then execute a function
#that uses these variables.

del session #closes the session and deletes the instance

#session.close() only closes the session

Note

If Matlab is not properly installed, the opening of the MatlabSession will fail.

Note

If the command matlab.MatlabSesseion() returns the RuntimeError: error loading matlab engine: Cannot load library libeng.dll: The specified procedure could not be found., there is a version conflict between librarys loaded by itom/MatlabSession. One known conflict happens (Matlab version 2015), while the libraries icuio54.dll, icule54.dll, icuuc54.dll, icuin54.dll are loaded by the libeng.dll. One possible workaround is to copy the library files icuio54.dll, icule54.dll, icuuc54.dll, icuin54.dll from the {MatlabRoot}/bin/win64 folder into the {itomRoot}/lib folder.

«  8.5. Python-Module matplotlib   ::   Contents   ::   8.7. Reload modified modules  »