MATLAB: How to make a script return an output argument in python

python

Hi I have linked python to matlab. I am running a script written in MATLAB in python. I am using as reference
I want my script to return the variable in my python window. How i can do it? Can i avoid this without converting it to a function?
b = 5;
h = 3;
a = 0.5*(b.* h)
import matlab.engine
eng = matlab.engine.start_matlab()
eng.triarea(nargout=0)

Best Answer

Scripts do not return output arguments, but they do store results in variables in the base workspace [1]. You can access the MATLAB engine workspace from Python [2].
Example
>>> import matlab.engine
>>> eng = matlab.engine.start_matlab()
>>> eng.triarea(nargout=0)
a =
7.5000
>>> a = eng.workspace['a'] # get the variable 'a' from the workspace
>>> a
7.5
>>>
References