You need to install the python engine for matlab. Please note that the python version of your distribution must be compatible with the matlab version installed. For example python 3.12 (shipped with Ubuntu 24.04) is only compatible with Matlab 2024.
For example
cd usr/local/MATLAB/R2024b/extern/engines/python |
sudo python3 setup.py install |
- install jupyter etc |
sudo apt-get install python3-setuptools |
/usr/bib/python3 -m pip install --user jupyter |
sudo apt-get remove python3-pexpect |
/usr/bib/python3 -m pip install --user pexpect |
/usr/bin/python3 -m pip install --user matlabkernel |
You need to install via the emacs package system ob-ipython (or directly in ob-ipython
Also note, depending on your python version, you might consider ob-ipython with a slightly different client.py file, found in ob-ipython-fork
Run
/usr/bin/python3 in the python prompt: import matlab.engine eng = matlab.engine.start_matlab() the eng command needs some time to run. When finished run now eng.quit()
(setq org-confirm-babel-evaluate nil) ;don't prompt me to confirm every time I want to evaluate a block
;;; display/update images in the buffer after I evaluate
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)
(add-to-list 'org-src-lang-modes '("matlab" . matlab))
(setq python-shell-interpreter "python3")
;; set default headers for convenience
(setq org-babel-default-header-args:matlab
'((:results . "output replace")
(:session . "matlab")
(:kernel . "matlab")
(:exports . "code")
(:cache . "no")
(:noweb . "no")
(:hlines . "no")
(:tangle . "no")))
(defalias 'org-babel-execute:matlab 'org-babel-execute:ipython)
(defalias 'org-babel-prep-session:matlab 'org-babel-prep-session:ipython)
(defalias 'org-babel-matlab-initiate-session 'org-babel-ipython-initiate-session)Then use the following example
\begin{align*}
p_0&=\frac{15}{53}=0.283019
λ_p &=2.57583\
p0&± λ1-\frac{α {2}}\sqrt{\frac{p0(1-p0)}{n}}= 0.283019 ± 2.57583⋅ 0.0618762\
p0&± λ1-\frac{α {2}}\sqrt{\frac{p0(1-p0)}{n}}=0.283019 ± 0.159383
\end{align*}