client

Connect to network machine running MATLAB to run scripts.

A way to run MATLAB scripts inside python scripts. Meant to run things until I have time to port them to Python. It’s meant to match the gadgetron client.

mr_utils.matlab.client.client_get(varnames, host=None, port=None, bufsize=None)[source]

Get variables from remote MATLAB workspace into python.

Parameters:
  • varnames (list) – List of names of variables in MATLAB workspace to get.
  • host (str, optional) – host/ip-address of server running MATLAB.
  • port (int, optional) – port of host to connect to.
  • bufsize (int, optional) – Number of bytes to transmit/recieve at a time.
Returns:

vals – Contents of MATLAB workspace.

Return type:

dict

Raises:

ValueError – When transfered matlab workspace file cannot be read. When varnames is not a list type.

Notes

Notice that varnames should be a list of strings.

mr_utils.matlab.client.client_put(varnames, host=None, port=None, bufsize=None)[source]

Put variables from python into MATLAB workspace.

Parameters:
  • varnames (dict) – Python variables to be injected into MATLAB workspace.
  • host (str, optional) – host/ip-address of server running MATLAB.
  • port (int, optional) – port of host to connect to.
  • bufsize (int, optional) – Number of bytes to transmit/recieve at a time.
Returns:

Return type:

None

Raises:

ValueError – When varnames is not a dictionary object.

Notes

Notice that varnames should be a dictionary: keys are the desired names of the variables in the MATLAB workspace and values are the python variables.

mr_utils.matlab.client.client_run(cmd, host=None, port=None, bufsize=None)[source]

Run command on MATLAB server.

Parameters:
  • cmd (str) – MATLAB command.
  • host (str, optional) – host/ip-address of server running MATLAB.
  • port (int, optional) – port of host to connect to.
  • bufsize (int, optional) – Number of bytes to transmit/recieve at a time.
Returns:

Return type:

None

Notes

If values are not provided (i.e., None) the values for host, port, bufsize will be taken from the active profile in profiles.config.

mr_utils.matlab.client.get_socket(host, port, bufsize)[source]

Open a socket to the machine running MATLAB.

Parameters:
  • host (str) – IP address of machine running MATLAB.
  • port (int) – port to connect to.
  • bufsize (int) – Buffer size to use for communication.
Returns:

  • sock (socket.socket) – TCP socket for communication
  • host (str) – host ip address
  • port (int) – Port we’re communicating over
  • bufsize (int) – Buffer size to use during communication

Notes

If values are not provided (i.e., None) the values for host, port, bufsize will be taken from the active profile in profiles.config.