MatlabProcess
-
class
compas.com.
MatlabProcess
(matlab_exec=None, ws_data=None, ws_filename=None, timeout=None, verbose=True)[source] Bases:
object
Communicate with Matlab through a subprocess.
- Parameters
matlab_exec (str, optional) – Path to the Matlab executable. Defaults to
matlab
.ws_data (dict, optional) – Workspace data to be loaded at startup. Defaults to an empty dict.
ws_filename (str, optional) – Filename for workspace storage. Defaults to
'./workspace.mat'
.
Examples
>>> m = MatlabProcess()
>>> m.start() >>> m.write_value('a', 37) >>> m.run_command('tf = isprime(a);') >>> m.read_workspace() >>> m.stop() >>> print(m.ws_data)
>>> m.write_value('a', 17) >>> m.run_command('res = isprime(a);') >>> m.read_value('res') True
>>> m.run_command('res = isprime(a);', ivars={'a': 17}) >>> m.read_value('res') True
>>> m.run_command('res = isprime(a);', ivars={'a': 17}, ovars={'res': None}) {'res': True}
Methods
__init__
([matlab_exec, ws_data, …])init
()read_value
(name[, default])run_command
(command[, ivars, ovars])Run a command in Matlab.
start
([options])Start the subprocess.
stop
()write_value
(name, value)