%PYRUN Run Python statements and expressions in the same Python interpreter session.
%
%   PYRUN(CODE) executes Python expressions, CODE, which can be provided as a string,
%   cellstr or a char array or a Python Code object. Multiline expressions can be
%   provided as a string array where each item represents a line.
%
%   [ OUTVARS ] = PYRUN(CODE, OUTPUTS) executes the CODE and returns any variable
%   generated by Python to MATLAB, by specifying the names of the Python variables
%   in the OUTPUTS and capturing the returned values in OUTVARS. OUTPUTS can be provided
%   as a string, cellstr or a char array.
%
%   [ OUTVARS ] = PYRUN(CODE, OUTPUTS, varargin<INPUTS>) executes the CODE and returns
%   OUTPUTS and assigns them to OUTVARS, using the MATLAB data passed by varargin<INPUTS>.
%   varargin<INPUTS> can be used to pass MATLAB data to the Python expression as
%   name-value pairs, where name is the name of the Python variable to be assigned and
%   the value is the MATLAB data or a variable name in an accessible workspace.
%   The varargin<INPUTS> can only be used to pass data that can automatically be converted
%   to a Python type.
%
%   Example:
%   meaning = 42;
%   [ma, mb] = pyrun(["a = x", "b = a + y"], ["a", "b"], x = 4, y = meaning);
%   mc = pyrun("c = a + 5", "c");
%
%   In the above example, the value 4 and 42 are assigned to Python variables 'x' and 'y'
%   respectively. Once the two lines of code are executed by Python two new variables are
%   generated, 'a' with the value of 4 and 'b' with the value of 46. The 'a' and 'b' are returned
%   to MATLAB and assigned to 'ma' and 'mb' respectively.
%
%   In the second pyrun call, a new variable, 'c', is generated, returned and assigned to 'mc'.
%   In this call, the value of variable 'a' is used from the previous pyrun call. This is because
%   all variables generated on the Python side will be persistent across different pyrun
%   calls, when interacting with the same Python interpreter session. When you are running
%   Python interpreter in OutOfProcess mode, you have the option to terminate and start a
%   new Python interpreter, by first calling
%
%   terminate(pyenv)
%
%   then calling a Python function using py. or run a pyrun/pyrunfile command.
%

% Copyright 2021 The MathWorks, Inc.
