cobra.io.mat Module Contents


extract the compartment from the id string


translate an array x into a MATLAB cell array

cobra.io.mat.load_matlab_model(infile_path, variable_name=None, inf=inf)[source]

Load a cobra model stored as a .mat file

  • infile_path (str) – path to the file to to read
  • variable_name (str, optional) – The variable name of the model in the .mat file. If this is not specified, then the first MATLAB variable which looks like a COBRA model will be used
  • inf (value) – The value to use for infinite bounds. Some solvers do not handle infinite values so for using those, set this to a high numeric value.

The resulting cobra model

Return type:


cobra.io.mat.save_matlab_model(model, file_name, varname=None)[source]

Save the cobra model as a .mat file.

This .mat file can be used directly in the MATLAB version of COBRA.

  • model (cobra.core.Model.Model object) – The model to save
  • file_name (str or file-like object) – The file to save to
  • varname (string) – The name of the variable within the workspace

create a dict mapping model attributes to arrays

cobra.io.mat.from_mat_struct(mat_struct, model_id=None, inf=inf)[source]

create a model from the COBRA toolbox struct

The struct will be a dict read in by scipy.io.loadmat


ensure success of a pymatbridge operation

cobra.io.mat.model_to_pymatbridge(model, variable_name="model", matlab=None)[source]

send the model to a MATLAB workspace through pymatbridge

This model can then be manipulated through the COBRA toolbox

  • variable_name (str) – The variable name to which the model will be assigned in the MATLAB workspace
  • matlab (None or pymatbridge.Matlab instance) – The MATLAB workspace to which the variable will be sent. If this is None, then this will be sent to the same environment used in IPython magics.