Using MATLAB on Google Colab
Google recently announced that Colab Terminal is Now Free For All Users and a few MathWorkers immediately thought to themselves "Well, this makes it rather easier to use MATLAB there then!" and an internal conversation on how to do it kicked off.
This is all rather experimental and rough around the edges and but I'm excited so wanted to share with you all what we got working. I wouldn't suggest using this for production work but maybe you'll have fun playing with it too?
Installing MATLAB into Google Colab and using it in terminal mode
Once you've opened the Colab terminal, run the following commands to install MATLAB:
wget https://www.mathworks.com/mpm/glnxa64/mpm
chmod +x mpm
./mpm install --release=R2025a --products=MATLAB

Once this has completed, run MATLAB like this:
/usr/local/MATLAB/R2025a/bin/matlab -nodesktop -licmode onlinelicensing
You'll be prompted:
Please enter your MathWorks Account email address and press Enter:
Do as it asks and you'll get the following prompt:
You need a one-time password to sign in. To get a one-time password, follow these steps:
1. Go to https://www.mathworks.com/mwa/otp
2. Enter your MathWorks Account email address.
3. Copy the generated one-time password.
4. Return here and enter the password.
Follow the instructions and you should be greeted with MATLAB running in the terminal:

Since the Colab terminal doesn't support it, you can't do anything graphical such as plotting and there's no desktop but this is a step in the right direction.
Attempting to use the MATLAB Kernel for Jupyter didn't work
The MATLAB kernel for Jupyter has been available for a couple of years now and has improved quite a bit since I first wrote about it in January 2023. I installed this into Colab with the following command at the terminal
pip install jupyter-matlab-proxy
This made the MATLAB Kernel available in the Runtime->Change runtime type section of the Colab menu and it allowed me to select it.

However, on attempting to run any MATLAB commands in a notebook, it fell back to the Python kernel.

It seems that using user-installed kernels is not currently supported by Colab.
Use the MATLAB Engine for Python in Google Colab
I have MATLAB installed in Colab and I can run Python notebooks there. So, the next logical pathway to using MATLAB in Colab is to do so via the MATLAB Engine for Python. Install the engine by running the following in the Colab terminal
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/MATLAB/R2025a/bin/glnxa64
python3 -m pip install matlabengine
Now, you can create a Python notebook and use the MATLAB engine there. I tried something very simple, just to check if the basics were there.
import matlab.engine
eng = matlab.engine.start_matlab("-licmode onlinelicensing")
eng.sqrt(4.0)

Over to you
These are just baby-steps to show that this can be done at all. This isn't an officially supported workflow by MathWorks; it's just a few geeks playing around right now. Is this minimal set of functionality useful to you? What more would you like to see? Do my instructions work for you?
댓글
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.