<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Matlab_is_also_just_a_Python_package</id>
	<title>Matlab is also just a Python package - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Matlab_is_also_just_a_Python_package"/>
	<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Matlab_is_also_just_a_Python_package&amp;action=history"/>
	<updated>2026-06-02T08:49:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Matlab_is_also_just_a_Python_package&amp;diff=393&amp;oldid=prev</id>
		<title>Davrot at 16:59, 17 October 2025</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Matlab_is_also_just_a_Python_package&amp;diff=393&amp;oldid=prev"/>
		<updated>2025-10-17T16:59:28Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:59, 17 October 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== The goal ==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Remote controlling Matlab from Python using the Matlab engine package. (Note: A similar approach can be used with C/C++ instead of Python.)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Remote controlling Matlab from Python using the Matlab engine package. (Note: A similar approach can be used with C/C++ instead of Python.)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l160&quot;&gt;Line 160:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 159:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;)  # SyntaxError: Incorrect use of &amp;#039;=&amp;#039; operator. Assign a value to a variable using &amp;#039;=&amp;#039; and compare values for equality using &amp;#039;==&amp;#039;.&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;)  # SyntaxError: Incorrect use of &amp;#039;=&amp;#039; operator. Assign a value to a variable using &amp;#039;=&amp;#039; and compare values for equality using &amp;#039;==&amp;#039;.&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exchanging data with Matlab &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;bi-directionally &lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exchanging data with Matlab &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;bidirectionally &lt;/ins&gt;==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import matlab.engine&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import matlab.engine&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import matlab&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import matlab&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki:diff:1.41:old-243:rev-393:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Matlab_is_also_just_a_Python_package&amp;diff=243&amp;oldid=prev</id>
		<title>Davrot: Created page with &quot;== The goal == Remote controlling Matlab from Python using the Matlab engine package. (Note: A similar approach can be used with C/C++ instead of Python.)  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  == Installing Matlab under Python == [https://de.mathworks.com/support/requirements/python-compatibility.html Versions of Python Compatible with MATLAB Products by Release]  Obviously you need a working Matlab and Python installation first. Then…  === Linux...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Matlab_is_also_just_a_Python_package&amp;diff=243&amp;oldid=prev"/>
		<updated>2025-10-17T14:03:17Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== The goal == Remote controlling Matlab from Python using the Matlab engine package. (Note: A similar approach can be used with C/C++ instead of Python.)  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  == Installing Matlab under Python == [https://de.mathworks.com/support/requirements/python-compatibility.html Versions of Python Compatible with MATLAB Products by Release]  Obviously you need a working Matlab and Python installation first. Then…  === Linux...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== The goal ==&lt;br /&gt;
Remote controlling Matlab from Python using the Matlab engine package. (Note: A similar approach can be used with C/C++ instead of Python.)&lt;br /&gt;
&lt;br /&gt;
Questions to [mailto:davrot@uni-bremen.de David Rotermund]&lt;br /&gt;
&lt;br /&gt;
== Installing Matlab under Python ==&lt;br /&gt;
[https://de.mathworks.com/support/requirements/python-compatibility.html Versions of Python Compatible with MATLAB Products by Release]&lt;br /&gt;
&lt;br /&gt;
Obviously you need a working Matlab and Python installation first. Then…&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
Open a terminal and do this (please adapt to your Matlab and Python version / installation path). And make sure that you use the correct Python installation for this operation, otherwise you will be confused why it will not work.&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;cd /tools/matlab2023b/extern/engines/python/&lt;br /&gt;
/data_1/davrot/P3.11/bin/python3 ./setup.py install&amp;lt;/syntaxhighlight&amp;gt;You get something like this as a response:&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;running install&lt;br /&gt;
running bdist_egg&lt;br /&gt;
running egg_info&lt;br /&gt;
creating dist/matlabengine.egg-info&lt;br /&gt;
writing dist/matlabengine.egg-info/PKG-INFO&lt;br /&gt;
writing dependency_links to dist/matlabengine.egg-info/dependency_links.txt&lt;br /&gt;
writing top-level names to dist/matlabengine.egg-info/top_level.txt&lt;br /&gt;
writing manifest file &amp;#039;dist/matlabengine.egg-info/SOURCES.txt&amp;#039;&lt;br /&gt;
/data_1/davrot/P3.11/lib/python3.11/site-packages/setuptools/command/egg_info.py:643: SetuptoolsDeprecationWarning: Custom &amp;#039;build_py&amp;#039; does not implement &amp;#039;get_data_files_without_manifest&amp;#039;.&lt;br /&gt;
Please extend command classes from setuptools instead of distutils.&lt;br /&gt;
  warnings.warn(&lt;br /&gt;
reading manifest file &amp;#039;dist/matlabengine.egg-info/SOURCES.txt&amp;#039;&lt;br /&gt;
writing manifest file &amp;#039;dist/matlabengine.egg-info/SOURCES.txt&amp;#039;&lt;br /&gt;
installing library code to build/bdist.linux-x86_64/egg&lt;br /&gt;
running install_lib&lt;br /&gt;
running build_py&lt;br /&gt;
creating build&lt;br /&gt;
creating build/lib&lt;br /&gt;
creating build/lib/matlab&lt;br /&gt;
copying dist/matlab/__init__.py -&amp;gt; build/lib/matlab&lt;br /&gt;
creating build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/matlabengine.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/basefuture.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/fevalfuture.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/__init__.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/engineerror.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/enginehelper.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/matlabfuture.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/futureresult.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
copying dist/matlab/engine/enginesession.py -&amp;gt; build/lib/matlab/engine&lt;br /&gt;
creating build/bdist.linux-x86_64&lt;br /&gt;
creating build/bdist.linux-x86_64/egg&lt;br /&gt;
creating build/bdist.linux-x86_64/egg/matlab&lt;br /&gt;
creating build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/matlabengine.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/basefuture.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/fevalfuture.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/__init__.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/engineerror.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/_arch.txt -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/enginehelper.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/matlabfuture.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/futureresult.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/engine/enginesession.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab/engine&lt;br /&gt;
copying build/lib/matlab/__init__.py -&amp;gt; build/bdist.linux-x86_64/egg/matlab&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/matlabengine.py to matlabengine.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/basefuture.py to basefuture.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/fevalfuture.py to fevalfuture.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/__init__.py to __init__.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/engineerror.py to engineerror.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/enginehelper.py to enginehelper.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/matlabfuture.py to matlabfuture.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/futureresult.py to futureresult.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/engine/enginesession.py to enginesession.cpython-311.pyc&lt;br /&gt;
byte-compiling build/bdist.linux-x86_64/egg/matlab/__init__.py to __init__.cpython-311.pyc&lt;br /&gt;
creating build/bdist.linux-x86_64/egg/EGG-INFO&lt;br /&gt;
copying dist/matlabengine.egg-info/PKG-INFO -&amp;gt; build/bdist.linux-x86_64/egg/EGG-INFO&lt;br /&gt;
copying dist/matlabengine.egg-info/SOURCES.txt -&amp;gt; build/bdist.linux-x86_64/egg/EGG-INFO&lt;br /&gt;
copying dist/matlabengine.egg-info/dependency_links.txt -&amp;gt; build/bdist.linux-x86_64/egg/EGG-INFO&lt;br /&gt;
copying dist/matlabengine.egg-info/top_level.txt -&amp;gt; build/bdist.linux-x86_64/egg/EGG-INFO&lt;br /&gt;
zip_safe flag not set; analyzing archive contents...&lt;br /&gt;
matlab.__pycache__.__init__.cpython-311: module references __file__&lt;br /&gt;
matlab.__pycache__.__init__.cpython-311: module references __path__&lt;br /&gt;
matlab.engine.__pycache__.__init__.cpython-311: module references __file__&lt;br /&gt;
creating &amp;#039;dist/matlabengine-23.2-py3.11.egg&amp;#039; and adding &amp;#039;build/bdist.linux-x86_64/egg&amp;#039; to it&lt;br /&gt;
removing &amp;#039;build/bdist.linux-x86_64/egg&amp;#039; (and everything under it)&lt;br /&gt;
Processing matlabengine-23.2-py3.11.egg&lt;br /&gt;
creating /data_1/davrot/P3.11/lib/python3.11/site-packages/matlabengine-23.2-py3.11.egg&lt;br /&gt;
Extracting matlabengine-23.2-py3.11.egg to /data_1/davrot/P3.11/lib/python3.11/site-packages&lt;br /&gt;
Adding matlabengine 23.2 to easy-install.pth file&lt;br /&gt;
&lt;br /&gt;
Installed /data_1/davrot/P3.11/lib/python3.11/site-packages/matlabengine-23.2-py3.11.egg&lt;br /&gt;
Processing dependencies for matlabengine==23.2&lt;br /&gt;
Finished processing dependencies for matlabengine==23.2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
Open a Power Shell as administrator under Windows and do this:&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;cd &amp;quot;C:\Program Files\MATLAB\R2023b\extern\engines\python&amp;quot;&lt;br /&gt;
python.exe .\setup.py install&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Start the engine ==&lt;br /&gt;
Under Python we now can connect to Matlab:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import matlab.engine&lt;br /&gt;
&lt;br /&gt;
eng = matlab.engine.start_matlab()&amp;lt;/syntaxhighlight&amp;gt;If now error message pops up then you should be ready to go!&lt;br /&gt;
&lt;br /&gt;
== First test ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import numpy as np&lt;br /&gt;
import matlab.engine&lt;br /&gt;
&lt;br /&gt;
eng = matlab.engine.start_matlab()&lt;br /&gt;
&lt;br /&gt;
a = eng.rand(100, 10)&lt;br /&gt;
print(type(a))  # --&amp;gt; &amp;lt;class &amp;#039;mlarray.double&amp;#039;&amp;gt;&lt;br /&gt;
a_np = np.array(a)&lt;br /&gt;
print(type(a_np)) # --&amp;gt; &amp;lt;class &amp;#039;numpy.ndarray&amp;#039;&amp;gt;&lt;br /&gt;
print(a_np.shape) # --&amp;gt; (100, 10)&lt;br /&gt;
print(a_np.dtype) # --&amp;gt; float64&amp;lt;/syntaxhighlight&amp;gt;You may want to read additional information about the whole ordeal:&lt;br /&gt;
&lt;br /&gt;
* [https://de.mathworks.com/help/matlab/matlab_external/matlab-arrays-as-python-variables.html MATLAB Arrays as Python Variables]&lt;br /&gt;
* [https://de.mathworks.com/help/matlab/matlab_external/use-matlab-arrays-in-python.html Use MATLAB Arrays in Python]&lt;br /&gt;
* [https://de.mathworks.com/help/matlab/matlab_external/pass-data-to-matlab-from-python.html Pass Data to MATLAB from Python]&lt;br /&gt;
* [https://de.mathworks.com/help/matlab/matlab_external/handle-data-returned-from-matlab-to-python.html Handle Data Returned from MATLAB to Python]&lt;br /&gt;
&lt;br /&gt;
== Eval ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import matlab.engine&lt;br /&gt;
&lt;br /&gt;
eng = matlab.engine.start_matlab()&lt;br /&gt;
&lt;br /&gt;
eng.eval(&amp;quot;clear all&amp;quot;, nargout=0)&lt;br /&gt;
eng.eval(&amp;quot;a = rand(100,10);&amp;quot;, nargout=0)&lt;br /&gt;
eng.eval(&amp;quot;whos&amp;quot;, nargout=0)&lt;br /&gt;
eng.eval(&amp;quot;figure(1);&amp;quot;, nargout=0)&lt;br /&gt;
eng.eval(&amp;quot;plot(a)&amp;quot;, nargout=0)&lt;br /&gt;
&lt;br /&gt;
input(&amp;quot;Press enter to continue&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;And you get this result if you use the Power Shell:&lt;br /&gt;
&lt;br /&gt;
PS C:&amp;amp;#x3E; python.exe .1.py Name Size Bytes Class Attributes&lt;br /&gt;
&lt;br /&gt;
a 100x10 8000 double&lt;br /&gt;
&lt;br /&gt;
Press enter to continue&amp;lt;div class=&amp;quot;figure&amp;quot;&amp;gt;&lt;br /&gt;
[[File:2023-12-21_16-56.png|image1]]&lt;br /&gt;
&amp;lt;/div&amp;gt;If you use VS Code in cell mode, you will get a cold stare instead of the text output. You need to add&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# %%&lt;br /&gt;
%matplotlib widget&amp;lt;/syntaxhighlight&amp;gt;to your python code.&lt;br /&gt;
&lt;br /&gt;
== Getting data from the Matlab workspace ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import matlab.engine&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
eng = matlab.engine.start_matlab()&lt;br /&gt;
&lt;br /&gt;
eng.eval(&amp;quot;clear all&amp;quot;, nargout=0)&lt;br /&gt;
eng.eval(&amp;quot;a = rand(100,10);&amp;quot;, nargout=0)&lt;br /&gt;
data_mat = eng.workspace[&amp;quot;a&amp;quot;]&lt;br /&gt;
print(type(data_mat))  # --&amp;gt; &amp;lt;class &amp;#039;matlab.double&amp;#039;&amp;gt;&lt;br /&gt;
a = np.array(data_mat)&lt;br /&gt;
print(type(a)) # --&amp;gt; &amp;lt;class &amp;#039;numpy.ndarray&amp;#039;&amp;gt;&lt;br /&gt;
print(a.shape) # --&amp;gt; (100, 10)&lt;br /&gt;
print(a.dtype) # --&amp;gt; float64&amp;lt;/syntaxhighlight&amp;gt;An alternative is:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import matlab.engine&lt;br /&gt;
&lt;br /&gt;
eng = matlab.engine.start_matlab()&lt;br /&gt;
&lt;br /&gt;
eng.eval(&amp;quot;A = 1;&amp;quot;, nargout=0)&lt;br /&gt;
Output = eng.eval(&amp;quot;A&amp;quot;, nargout=1)&lt;br /&gt;
print(Output)  # --&amp;gt; 1.0&lt;br /&gt;
&lt;br /&gt;
Output = eng.eval(&lt;br /&gt;
    &amp;quot;A = 1&amp;quot;, nargout=1&lt;br /&gt;
)  # SyntaxError: Incorrect use of &amp;#039;=&amp;#039; operator. Assign a value to a variable using &amp;#039;=&amp;#039; and compare values for equality using &amp;#039;==&amp;#039;.&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exchanging data with Matlab bi-directionally ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import matlab.engine&lt;br /&gt;
import matlab&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
eng = matlab.engine.start_matlab()&lt;br /&gt;
&lt;br /&gt;
myrng = np.random.default_rng()&lt;br /&gt;
&lt;br /&gt;
a = myrng.random((100, 10))&lt;br /&gt;
b = myrng.random((100, 10))&lt;br /&gt;
c_py = a * b&lt;br /&gt;
&lt;br /&gt;
a_mat = matlab.double(a.tolist())&lt;br /&gt;
b_mat = matlab.double(b.tolist())&lt;br /&gt;
&lt;br /&gt;
eng.eval(&amp;quot;clear all&amp;quot;, nargout=0)&lt;br /&gt;
eng.workspace[&amp;quot;a&amp;quot;] = a_mat&lt;br /&gt;
eng.workspace[&amp;quot;b&amp;quot;] = b_mat&lt;br /&gt;
&lt;br /&gt;
eng.eval(&amp;quot;c = a .* b;&amp;quot;, nargout=0)&lt;br /&gt;
&lt;br /&gt;
c_mat = np.array(eng.workspace[&amp;quot;c&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
print(np.sum(np.abs(c_py - c_mat))) # --&amp;gt; 0.0&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
</feed>