MatlabClient

class compas.com.MatlabClient(verbose=False, interactive=False, workspace='base')[source]

Bases: object

Communicate with Matlab through Windows’ COM interface.

Parameters
  • verbose (bool) – If True, all commands and results will be printed in the Python console. Default is False.

  • interactive (bool) – If True, a Matlab console window will be visible. Default is False.

  • workspace (str) – The name of the Matlab workspace. Default is 'base'.

Notes

This implementation uses Windows’ COM interface to communicate with Matlab. Therefore, it is obviously only available on Windows. When an instance of this class is created, it automatically connects to Matlab, and initializes a lease that keeps the interface alive for at least 5 minutes such that subsequent calls can be executed immediately. After every call, the lease is renewed…

Examples

>>> matlab = MatlabClient(interactive=True)
>>> A = matlab.matrix_from_list([[1, 0, 1, 3], [2, 3, 4, 7], [-1, -3, -3, -4]])
>>> matlab.put('A', A)
>>> matlab.eval('[R, jb] = rref(A);')
>>> R = matlab.get('R')
>>> jb = matlab.get('jb')
>>> print(R)
>>> print(jb)

See also

compas.com.mlab.MatlabEngine, compas.com.mlab.MatlabSession, compas.com.mlab.MatlabProcess

Methods

__init__([verbose, interactive, workspace])

x.__init__(…) initializes x; see help(type(x)) for signature

double(a)

eval(cmd)

Evaluate a command from a string.

get(name)

Get the value of a variable in the workspace.

init()

list_from_matrix(A, m, n)

Convert a Matlab matrix to a Python list.

list_from_vector(a)

Convert a Matlab vector to a Python list.

matrix_from_array(a)

Make a Matlab-compatible matrix from a (Numpy) array.

matrix_from_list(A[, dtype])

Make a Matlab-compatible matrix from a list of lists.

put(name, value)

Put a variable in the Matlab workspace.

vector_from_array(a)

Make a Matlab-compatible vector from a (Numpy) array.

vector_from_list(a[, dtype])

Make a Matlab-compatible vector from a list.