{"id":18242,"date":"2025-09-04T04:04:22","date_gmt":"2025-09-04T08:04:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/deep-learning\/?p=18242"},"modified":"2025-09-29T11:32:47","modified_gmt":"2025-09-29T15:32:47","slug":"matlab-on-google-colab-train-a-model-in-matlab-export-to-tensorflow-and-test-in-python","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/09\/04\/matlab-on-google-colab-train-a-model-in-matlab-export-to-tensorflow-and-test-in-python\/","title":{"rendered":"MATLAB on Google Colab: Train a model in MATLAB, export to TensorFlow, and test in Python"},"content":{"rendered":"<h6><\/h6>\r\nAs you might have read from my dear colleague Mike on the <a href=\"https:\/\/blogs.mathworks.com\/matlab\/2025\/06\/27\/using-matlab-on-google-colab\/https:\/\/blogs.mathworks.com\/matlab\/2025\/06\/27\/using-matlab-on-google-colab\/\">MATLAB blog<\/a>, MATLAB now slots neatly into Google\u00ae Colab. Google Colab is a great sandbox for demos, workshops, or quick experiments. Students often ask us if they can leverage this infrastructure for their MATLAB project. Now you can!\r\n<h6><\/h6>\r\nLet me walk you through how you can leverage MATLAB on Google Colab for training an AI model and export it to TensorFlow (or ONNX) to call it from Python\u00ae.\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<table width=\"90%;\">\r\n<tbody>\r\n<tr style=\"border: solid 1px #bfbfbf; border-bottom: solid 2px #bfbfbf;\">\r\n<td style=\"padding: 10px; text-align: left; border: solid 1px #bfbfbf;\"><strong>What\u2019s new<\/strong><\/td>\r\n<td style=\"padding: 10px; text-align: left; border: solid 1px #bfbfbf;\"><strong>Why it matters<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"padding: 10px; text-align: left; border: solid 1px #bfbfbf;\"><strong>Integrated Terminal in Colab<\/strong><\/td>\r\n<td style=\"padding: 10px; text-align: left; border: solid 1px #bfbfbf;\">You get a full Bash shell, perfect for running installers or checking GPU status with <span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\">nvidia-smi<\/span><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"padding: 10px; text-align: left; border: solid 1px #bfbfbf;\"><a href=\"https:\/\/github.com\/mathworks-ref-arch\/matlab-dockerfile\/blob\/main\/MPM.md\"><strong>MATLAB Package Manager (mpm)<\/strong><\/a><\/td>\r\n<td style=\"padding: 10px; text-align: left; border: solid 1px #bfbfbf;\">With MPM you can install programmatically MATLAB plus any toolbox or support package via the terminal. In just one line: <span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\">mpm install matlab<\/span><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<h6><\/h6>\r\nBelow is a walkthrough that turns those pieces into a complete deep learning workflow.\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>1. Connect your notebook to a runtime with a GPU<\/strong><\/p>\r\nOnce you arrive on a new Colab notebook, the first thing to do is change the runtime type to T4 GPU, from the drop-down arrow next to the RAM and Disk consumption graphs.\r\n<h6><\/h6>\r\n&nbsp;\r\n\r\n<img decoding=\"async\" loading=\"lazy\" class=\"wp-image-18344 alignnone\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab1-1-1024x721.png\" alt=\"\" width=\"300\" height=\"211\" \/>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <img decoding=\"async\" loading=\"lazy\" class=\"wp-image-18347 alignnone\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab2-1-1024x769.png\" alt=\"\" width=\"299\" height=\"225\" \/>\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\nIn order to verify that you are indeed connected to a backend that has access to a GPU, you can run the following command in a cell (using the ! bang\u00a0 symbol to signal that it is a shell command, not a python command).\r\n<h6><\/h6>\r\n&nbsp;\r\n<div style=\"position:relative; background:#f9fafb; border:1px solid #d1d5db; border-radius:6px; padding:1rem; font-family:Consolas,monospace; color:#111827;\">\r\n  <button onclick=\"copyCode(this)\" style=\"position:absolute; top:8px; right:8px; background:#e5e7eb; color:#111827; border:1px solid #d1d5db; border-radius:4px; padding:4px 8px; font-size:12px; cursor:pointer;\">\r\n    Copy\r\n  <\/button>\r\n  <pre id=\"matlab-snippet\" style=\"margin:0; padding:0; border:none; background:none; color:inherit; white-space:pre; line-height:1.4;\"># In a Colab cell\r\n\r\n!nvidia-smi<\/pre><\/div>\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18251 size-full\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab3.png\" alt=\"!nvidia-smi command\" width=\"1430\" height=\"752\" \/>\r\n<h6><\/h6>\r\nUsers were always able to run shell commands as shown above in a notebook cell, but what is new is the ability to do the same from the convenience of a terminal in the free tier.\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>2. Open the terminal to install MATLAB in two lines<\/strong><\/p>\r\nClick <strong>Terminal <\/strong>on the bottom left of the page. This will open a new panel on the right, next to your notebook. You can run commands directly like\u00a0<span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\">nvidia-smi<\/span>.\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"1430\" height=\"526\" class=\"aligncenter size-full wp-image-18254\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab4.png\" alt=\"\" \/>\r\n<h6><\/h6>\r\nYou have access to the underlying file system in which the session runs. When opening the terminal, you are brought in <span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\">\/content<\/span>, at the root of your ephemeral virtual machine (bear in mind that anything in this machine won\u2019t persist automatically, you need to store your valuable data and results in Google Drive, that needs to be mounted manually.\r\n<h6><\/h6>\r\nHere, I provide you with a script that automates the installation of MATLAB using MPM.\r\n<h6><\/h6>\r\n<div style=\"position:relative; background:#f9fafb; border:1px solid #d1d5db; border-radius:6px; padding:1rem; font-family:Consolas,monospace; color:#111827;\">\r\n  <button onclick=\"copyCode(this)\" style=\"position:absolute; top:8px; right:8px; background:#e5e7eb; color:#111827; border:1px solid #d1d5db; border-radius:4px; padding:4px 8px; font-size:12px; cursor:pointer;\">\r\n    Copy\r\n  <\/button>\r\n  <pre id=\"matlab-snippet\" style=\"margin:0; padding:0; border:none; background:none; color:inherit; white-space:pre; line-height:1.4;\">wget https:\/\/www.mathworks.com\/mpm\/glnxa64\/mpm &amp;&amp; \\\r\nchmod +x mpm &amp;&amp; \\\r\n.\/mpm install --release=R2025a --destination=\/opt\/matlab --products=MATLAB &amp;&amp; \\\r\nln -fs \/opt\/matlab\/bin\/matlab \/usr\/local\/bin\/matlab &amp;&amp; \\\r\nMATLAB_DEPS_URL=\"https:\/\/raw.githubusercontent.com\/mathworks-ref-arch\/container-images\/main\/matlab-deps\/r2025a\/ubuntu22.04\/base-dependencies.txt\" &amp;&amp; \\\r\nMATLAB_DEPENDENCIES=base-dependencies.txt &amp;&amp; \\\r\nwget ${MATLAB_DEPS_URL} -O ${MATLAB_DEPENDENCIES} &amp;&amp; \\\r\nxargs -a ${MATLAB_DEPENDENCIES} -r apt-get install --no-install-recommends -y &amp;&amp; \\\r\nexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:\/opt\/matlab\/bin\/glnxa64 &amp;&amp; \\\r\npython3 -m pip install jupyter-matlab-proxy matlabengine==25.1.2 &amp;&amp; \\\r\nenv MWI_APP_PORT=3000 MWI_ENABLE_AUTH_TOKEN=False matlab-proxy-app &amp;<\/pre><\/div>\r\n<h6><\/h6>\r\nIt should take 2-3 min to install MATLAB (no toolboxes at this stage). The magic trick is the following code cell to serve the MATLAB desktop in another window of your web browser.\r\n<h6><\/h6>\r\n<div style=\"position:relative; background:#f9fafb; border:1px solid #d1d5db; border-radius:6px; padding:1rem; font-family:Consolas,monospace; color:#111827;\">\r\n  <button onclick=\"copyCode(this)\" style=\"position:absolute; top:8px; right:8px; background:#e5e7eb; color:#111827; border:1px solid #d1d5db; border-radius:4px; padding:4px 8px; font-size:12px; cursor:pointer;\">\r\n    Copy\r\n  <\/button>\r\n  <pre id=\"matlab-snippet\" style=\"margin:0; padding:0; border:none; background:none; color:inherit; white-space:pre; line-height:1.4;\">from google.colab import output\r\noutput.serve_kernel_port_as_window(3000, path='\/')<\/pre><\/div>\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"1430\" height=\"561\" class=\"aligncenter size-full wp-image-18257\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab5.png\" alt=\"\" \/>\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\nYou might get warning messages in red. Do not worry, those are not errors, I\u2019ll get to that at the end of the post.\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18293 size-full\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab6-1.png\" alt=\"\" width=\"1190\" height=\"467\" \/>\r\n\r\n&nbsp;\r\n\r\nThe first time you open MATLAB, you will be prompted for your MathWorks credentials.\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n&nbsp;\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>3. Add Deep Learning Toolbox (and friends)<\/strong><\/p>\r\nCheck that you can access the GPU by typing <span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\">gpuDevice<\/span>, only to realize that you might be missing a few dependencies.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"1412\" height=\"978\" class=\"aligncenter size-full wp-image-18296\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab7-1.png\" alt=\"\" \/>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\nDon\u2019t panic, you can install toolboxes as you go.\r\n<div style=\"position:relative; background:#f9fafb; border:1px solid #d1d5db; border-radius:6px; padding:1rem; font-family:Consolas,monospace; color:#111827;\">\r\n  <button onclick=\"copyCode(this)\" style=\"position:absolute; top:8px; right:8px; background:#e5e7eb; color:#111827; border:1px solid #d1d5db; border-radius:4px; padding:4px 8px; font-size:12px; cursor:pointer;\">\r\n    Copy\r\n  <\/button>\r\n  <pre id=\"matlab-snippet\" style=\"margin:0; padding:0; border:none; background:none; color:inherit; white-space:pre; line-height:1.4;\">.\/mpm install --release=R2025a --destination=\/opt\/matlab --products=Deep_Learning_Toolbox Statistics_and_Machine_Learning_Toolbox Parallel_Computing_Toolbox<\/pre><\/div>\r\nEach package name is the exact product code shown on the MathWorks website, on the <a href=\"https:\/\/www.mathworks.com\/products.html\">products list page<\/a>. Underscores replace spaces, but be careful to spell correctly because mpm is case sensitive!\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n<strong>Remember:<\/strong> Restart MATLAB after adding new toolboxes so they land on the path.\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>4. Launch MATLAB (again) &amp; Verify the GPU<\/strong><\/p>\r\nThis is the expected result of the previous command with everything installed correctly.\r\n<h6><\/h6>\r\n<pre>&gt;&gt; gpuDevice\r\n\r\n\r\nans = \r\n\r\n\u00a0 <span style=\"text-decoration: underline;\"><strong>CUDADevice<\/strong><\/span> with properties:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Name: 'Tesla T4'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Index: 1 (of 1)\r\n\u00a0\u00a0\u00a0 ComputeCapability: '7.5'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DriverModel: 'N\/A'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TotalMemory: 15828320256 (15.83 GB)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 AvailableMemory: 15720382464 (15.72 GB)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 DeviceAvailable: true\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DeviceSelected: true\r\n\r\n\u00a0 Show <span style=\"text-decoration: underline;\">all properties<\/span>.<\/pre>\r\n<h6><\/h6>\r\nYou should see the CUDA-enabled T4 appear in the output (or whatever GPU was assigned by Colab).\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>5. Hands-on Example: Time-Series Forecasting with an LSTM<\/strong><\/p>\r\nOne of my favorite applications of AI with MATLAB is predicting the future of a numerical sequence. In order to illustrate how you can leverage GPUs to speed up training of a neural network, I would like to point you to this example from the Deep Learning Toolbox documentation: <a href=\"https:\/\/www.mathworks.com\/help\/deeplearning\/ug\/time-series-forecasting-using-deep-learning.html\">Time Series Forecasting Using Deep Learning<\/a>\r\n<h6><\/h6>\r\nYou can open it directly in MATLAB with the following command:\r\n<h6><\/h6>\r\n<div style=\"position:relative; background:#f9fafb; border:1px solid #d1d5db; border-radius:6px; padding:1rem; font-family:Consolas,monospace; color:#111827;\">\r\n  <button onclick=\"copyCode(this)\" style=\"position:absolute; top:8px; right:8px; background:#e5e7eb; color:#111827; border:1px solid #d1d5db; border-radius:4px; padding:4px 8px; font-size:12px; cursor:pointer;\">\r\n    Copy\r\n  <\/button>\r\n  <pre id=\"matlab-snippet\" style=\"margin:0; padding:0; border:none; background:none; color:inherit; white-space:pre; line-height:1.4;\">openExample('nnet\/SequenceForecastingUsingDeepLearningExample')<\/pre><\/div>\r\n<h6><\/h6>\r\nThe following graph is generated if you run the entire live script. It illustrates the prediction of an electrical signal (simple periodic step function with some noise) in closed loop, meaning that after the first prediction of the last point of the signal, you \u201croll forward\u201d by feeding this prediction back into the model.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"560\" height=\"420\" class=\"aligncenter size-full wp-image-18266\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab8.png\" alt=\"\" \/>\r\n<h6><\/h6>\r\nThe part of the code that I want to highlight here is the creation of the LSTM architecture (LSTM stands for <a href=\"https:\/\/www.mathworks.com\/discovery\/lstm.html\">Long Short-Term Memory<\/a>).\r\n<h6><\/h6>\r\n<div style=\"position:relative; background:#f9fafb; border:1px solid #d1d5db; border-radius:6px; padding:1rem; font-family:Consolas,monospace; color:#111827;\">\r\n  <button onclick=\"copyCode(this)\" style=\"position:absolute; top:8px; right:8px; background:#e5e7eb; color:#111827; border:1px solid #d1d5db; border-radius:4px; padding:4px 8px; font-size:12px; cursor:pointer;\">\r\n    Copy\r\n  <\/button>\r\n  <pre id=\"matlab-snippet\" style=\"margin:0; padding:0; border:none; background:none; color:inherit; white-space:pre; line-height:1.4;\">layers = [\r\n\u00a0\u00a0\u00a0 sequenceInputLayer(numChannels)\r\n\u00a0\u00a0\u00a0 lstmLayer(128)\r\n\u00a0\u00a0\u00a0 fullyConnectedLayer(numChannels)];\r\n\r\n<\/pre><\/div>\r\nYou will then need to specify training options and kick off the training of the network. \u00a0On the T4 the training finishes in ~1 min.\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18323 \" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab9-1.png\" alt=\"\" width=\"608\" height=\"345\" \/>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>6. Export the network to TensorFlow<\/strong><\/p>\r\nInstall the Deep Learning Toolbox Converter for TensorFlow Models support package (no need to restart MATLAB in this case).\r\n\r\n<img decoding=\"async\" loading=\"lazy\" width=\"624\" height=\"334\" class=\"aligncenter size-full wp-image-18272\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab10.png\" alt=\"\" \/>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\nTo export the network to TensorFlow, type:\r\n<div style=\"position:relative; background:#f9fafb; border:1px solid #d1d5db; border-radius:6px; padding:1rem; font-family:Consolas,monospace; color:#111827;\">\r\n  <button onclick=\"copyCode(this)\" style=\"position:absolute; top:8px; right:8px; background:#e5e7eb; color:#111827; border:1px solid #d1d5db; border-radius:4px; padding:4px 8px; font-size:12px; cursor:pointer;\">\r\n    Copy\r\n  <\/button>\r\n  <pre id=\"matlab-snippet\" style=\"margin:0; padding:0; border:none; background:none; color:inherit; white-space:pre; line-height:1.4;\">exportNetworkToTensorFlow(net,\"forecast_timeseries\");<\/pre><\/div>\r\nforecast_timeseries (a folder + HDF5 file) now lives under \/content.\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>7. Round-trip test in Python<\/strong><\/p>\r\nBack in a notebook cell, type the following.\r\n<h6><\/h6>\r\n<pre>import forecast_timeseries\r\nmodel = forecast_timeseries.load_model()\r\nmodel.summary()<\/pre>\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"wp-image-18326 alignnone\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab11-1-1024x358.png\" alt=\"\" width=\"580\" height=\"203\" \/>\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\nGrab the same test signal from MATLAB via the <strong>MATLAB Engine for Python<\/strong> (already installed by the previous terminal commands). Initiate a connection to the engine running in the Google Colab session, by entering <span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\"><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.engine.shareengine.html\">matlab.engine.shareEngine<\/a><\/span> in the MATLAB command window.\r\n<h6><\/h6>\r\n<pre>import matlab.engine\r\n\r\neng = matlab.engine.find_matlab()[0]\u00a0\u00a0\u00a0 # attach to running session\r\n\r\nm = matlab.engine.connect_matlab(eng)<\/pre>\r\n&nbsp;\r\n\r\nThen cast the variable from the MATLAB workspace into Numpy arrays in the Colab Notebook.\r\n<h6><\/h6>\r\n<pre>import numpy as np\r\n\r\nX = m.workspace['X']\r\n\r\nX = np.array(X)\r\n\r\nX = np.expand_dims(X, axis=0)\r\n\r\n# X.shape \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\r\nY = model.predict(X)<\/pre>\r\n<h6><\/h6>\r\nFinally, plot Y against the MATLAB reference to confirm fidelity.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"559\" height=\"413\" class=\"aligncenter size-full wp-image-18278\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab12.png\" alt=\"\" \/>\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>8. Gotchas &amp; pro tips<\/strong><\/p>\r\n\r\n<ul>\r\n \t<li><strong>Session restarts<\/strong>: Colab VMs expire after ~12 h. Keep the install script in a cell so you can re-run everything quickly.<\/li>\r\n \t<li><strong>Serving the MATLAB web desktop:<\/strong> The <a href=\"https:\/\/github.com\/mathworks\/matlab-proxy\"><span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\">matlab-proxy<\/span><\/a> Python package, installed via <span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\">pip<\/span>, provides the <span style=\"font-family: Consolas, Monaco, monospace; font-size: inherit;\">matlab-proxy-app<\/span> executable. When launched, it sets up a lightweight web server that forwards a MATLAB session to your browser. The UI includes controls for starting\/stopping MATLAB.<\/li>\r\n \t<li><strong>Forwarding ports<\/strong>: The helper script forwards the MATLAB desktop as another browser window through another port of the same machine. If it stalls, verify the port isn\u2019t blocked. This is an advanced maneuver that Google Colab offers for running servers like Flask or TensorBoard in another tab: <a href=\"https:\/\/colab.research.google.com\/notebooks\/snippets\/advanced_outputs.ipynb#scrollTo=6Ugsim80WVuq\">advanced_outputs.ipynb<\/a><\/li>\r\n \t<li><strong>Support packages vs. toolboxes<\/strong>: Toolbox installs require a MATLAB restart; add-on support packages (e.g., the TensorFlow converter) do not.<\/li>\r\n \t<li><strong>Licensing<\/strong>: An Individual or Campus-Wide license works fine. Trial licenses also work\u2014just watch the 30-day timer.<\/li>\r\n<\/ul>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 20px; color: #c04c0b;\"><strong>Wrapping up<\/strong><\/p>\r\nIn under ten minutes you can:\r\n<ol>\r\n \t<li>Provision a free GPU in Colab.<\/li>\r\n \t<li>Spin up full MATLAB with mpm (to run via the web desktop or with the MATLAB Engine for Python as mentioned in Mike\u2019s post).<\/li>\r\n \t<li>Train a deep learning model on the GPU.<\/li>\r\n \t<li>Export the network to TensorFlow.<\/li>\r\n \t<li>Validate it side-by-side in Python\u2014all within the same environment.<\/li>\r\n<\/ol>\r\nThis workflow bridges two worlds: ease of use for engineering workflows with MATLAB, and access to GPUs offered by Google Colab to learn about AI by training your own models. It\u2019s perfect for teaching, quick prototyping, or sharing reproducible research with colleagues.\r\n<h6><\/h6>\r\nHere is my colab notebook in case you want to skip to the result: <a href=\"https:\/\/gist.github.com\/yanndebray\/e2a32d39c77e92934ef40b276c700de7\">MATLABonColab.ipynb<\/a>\r\n<h6><\/h6>\r\nHappy hacking, and let me know what you build! \ud83d\udc4b\ud83c\udffb\r\n<h6><\/h6>\r\n&nbsp;\r\n\r\n<em>Special thanks to Daniele Sportillo and Prabhakar Kumar who pointed me to this exciting topic.<\/em>\r\n\r\n\r\n<script>\r\nfunction copyCode(btn) {\r\n  const code = btn.parentElement.querySelector(\"pre\").textContent.trim();\r\n  if (navigator.clipboard) {\r\n    navigator.clipboard.writeText(code).then(() => {\r\n      btn.textContent = \"Copied!\";\r\n      setTimeout(() => btn.textContent = \"Copy\", 1500);\r\n    }).catch(() => fallbackCopy(code, btn));\r\n  } else {\r\n    fallbackCopy(code, btn);\r\n  }\r\n}\r\nfunction fallbackCopy(text, btn) {\r\n  const ta = document.createElement(\"textarea\");\r\n  ta.value = text;\r\n  document.body.appendChild(ta);\r\n  ta.select();\r\n  document.execCommand(\"copy\");\r\n  document.body.removeChild(ta);\r\n  btn.textContent = \"Copied!\";\r\n  setTimeout(() => btn.textContent = \"Copy\", 1500);\r\n}\r\n<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/09\/colab2-1.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\nAs you might have read from my dear colleague Mike on the MATLAB blog, MATLAB now slots neatly into Google\u00ae Colab. Google Colab is a great sandbox for demos, workshops, or quick experiments.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/09\/04\/matlab-on-google-colab-train-a-model-in-matlab-export-to-tensorflow-and-test-in-python\/\">read more >><\/a><\/p>","protected":false},"author":230,"featured_media":18347,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[39,42],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18242"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/users\/230"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/comments?post=18242"}],"version-history":[{"count":41,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18242\/revisions"}],"predecessor-version":[{"id":18386,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18242\/revisions\/18386"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/media\/18347"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/media?parent=18242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/categories?post=18242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/tags?post=18242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}