In recent releases of MATLAB you can select MATLAB code in the Editor or documentation and press F9 to evaluate it in MATLAB. To expand this functionality to outside MATLAB, I created a tool called RunSelectedCodeInMatlab. It works in two modes:
Print mode (F9): similar to what is available in MATLAB. It prints the selected code, line by line at MATLAB command.
Hidden mode (F10): The code won’t be printed at MATLAB command and won’t show up in the command history but variables are created in the workspace and outputs are shown (figures, untruncated outputs, etc.,).
This mode requires MATLAB Automation Server to be enabled and when you run the tool it will prompt to enable the Automation Server for you.
To use the tool:
1- Download and run it.
2- You must have MATLAB open when you run it. It will ask to enable MATLAB Automation Server for you. This is needed for the “hidden” mode to work.
3- Now select MATLAB code in any application (web browser, PDFs, word docs, etc.). You can select multiple lines of code.
4- Press F9 (for the print mode) or F10 (for the hidden mode).