MATLAB installation
Main authors: Fabrice Le Bars, Simon Rohou
Since 2019, MATLAB allows you to import Python packages into its environment. Codac offers a Python package dedicated to MATLAB, with the necessary adaptations to run in this environment (for example: indices starting at 1, alternatives to unsupported & and | operations, etc.). This Python package dedicated to MATLAB is called codac4matlab. See the related PyPI page.
Dependencies: Ensure you have MATLAB R2019b or later.
Python integration: Follow the instructions here to set up Python integration.
Install the Python package:
pip install codac4matlab
Once Codac is installed, you can use it in your MATLAB scripts using the following import command:
import py.codac4matlab.*
% Your code...
Known installation issues and possible workarounds
On some configurations, you might need to use
pip3instead ofpip, and/or--break-system-packagesparameter, e.g.pip3 install --break-system-packages codac4matlab
or
python3 -m pip install --break-system-packages codac4matlab
In some cases, you might have multiple Python installations at different locations on your system (possibly the same Python version can be installed separately at different locations, also some versions of Python might be installed but incompatible with your version of MATLAB). In MATLAB, try to examine the output of the
pyenvcommand to try to determine where is the Python installation that it uses and possibly run the pip install command from inside MATLAB command window with the!prefix e.g.!pip install codac4matlab, or from a Windows Administrator command prompt with the full path to the python executable e.g"C:\Python312\python.exe" -m pip install codac4matlab.Python virtual environments compatibility has not been tested.
MATLAB Online: you will need to run codac4matlabonline.m. Tweak it if it does not work for you. It might not be possible to view the VIBes viewer windows, possibly use the VIBes functions to save the desired pictures as a workaround.
MATLAB specificities
You might need to add as prefix
py.codac4matlab.to class or function names, e.g.py.codac4matlab.IntervalforIntervalto avoid potential name conflicts with other libraries, and/or do explicitely e.g.import py.codac4matlab.Interval; import py.codac4matlab.cos;instead of justimport py.codac4matlab.*depending on your needs.When we click on a Codac variable e.g.
IntervalVector(py.codac4matlab._core.IntervalVector), we do not get help. Please check codac.io for the documentation. Also, you can try typing e.g.X0.followed by the TAB key (assumingX0is apy.codac4matlab._core.IntervalVector) to get a list of suggestions of properties and methods.
Note
Check codac4matlab_usage.m example for some MATLAB specificities.
See also Codac v1 documentation for some remaining issues and potential workarounds.
Python to MATLAB conversions
Be sure that Python multiline strings are correctly converted to multiline MATLAB strings between
'. Remember that multiline statements in MATLAB need...before next line.Please also convert Python for loops to typical MATLAB for loops, same for if-else, += statements.
Potential problem with VIBes
One of the graphical outputs supported in Codac is the VIBes viewer.
VIBes uses a client/server architecture and reads its configuration from the .vibes.json file located in your home directory (typically $HOME). This file is automatically generated.
If you launch MATLAB with sudo, the HOME variable points to /root, and VIBes will not find the .vibes.json file, causing the display to fail.
A solution is to avoid using sudo. If required, run MATLAB with the correct HOME:
sudo HOME=/home/your_username matlab