How do I run MATLAB (.m) files in VSCode?

I am not able to figure out how to run MATLAB (.m) code in VSCode.

I have installed the MATLAB Extension for VSCode and added the path for the mlint file for MATLAB as stated in the extension.


VSCode identifies the file as a MATLAB file. However, the code won't run.

How can I run MATLAB code from within VSCode?


  • As of April 2023 the below is no longer the only way to run MATLAB from VSCode. See the answer by svenmk about the plugin by The MathWorks themselves.

    There is a way, this VSCode extension suggests that you can use it to run MATLAB code from within VSCode without having to open the MATLAB GUI. It does not invalidate the below though; you need to have a working, licensed MATLAB installation, which will be called in the background. Without a working, licensed MATLAB installation you cannot run MATLAB code.

    As MATLAB is proprietary, there are only two ways to run MATLAB code: by running the code from the MATLAB IDE (with a valid license of course), or by compiling it to an executable file with the MATLAB compiler.
    You might be able to get other IDEs to have syntax highlighting and typing-hints like MATLAB's own IDE through importing its mlint functionality, like you did, but that won't execute the code.

    Thus no, you cannot execute MATLAB code directly within VSCode, you can only covertly call the MATLAB engine from inside VSCode.

    A possible workaround would be to export your MATLAB code to C/C++ using the MATLAB Coder. You can then run the C/C++ code from within VSCode.