1. Create a MATLAB .desktop File
First, check if a MATLAB .desktop file already exists in /usr/share/applications/ or ~/.local/share/applications/. If it doesn't, you'll need to create one.
- Open a terminal (Ctrl+Alt+T).
- Create a new .desktop file for MATLAB. Replace <MATLAB_VERSION> with your MATLAB version (e.g., R2021b) and <YOUR_USERNAME> with your actual username.
nano ~/.local/share/applications/matlab.desktop
Add the following content to the file. Adjust the paths if your MATLAB installation is in a different location.
Icon=/usr/local/MATLAB/<MATLAB_VERSION>/toolbox/matlab/icons/Matlab_Logo.png
Exec=/usr/local/MATLAB/<MATLAB_VERSION>/bin/matlab -desktop
Comment=Start MATLAB - The Language of Technical Computing
Save and close the editor (Ctrl+O, Enter, Ctrl+X).
2. Associate .m Files with MATLAB
- Still in the terminal, set MATLAB as the default application for .m files using the mime-type association.
You'll see a prompt asking you to choose an application. If MATLAB is listed, select it by typing its number. If it's not listed, select the option to use a custom command, and enter the command you used in the Exec field of the MATLAB .desktop file.
3. Check the Association
Double-click an .m file in your file manager to check if it now opens in MATLAB.
Troubleshooting
- If MATLAB still doesn't show up in the "Open With" list, try logging out and logging back in, or rebooting your system.
- Ensure the .desktop file's Exec path correctly points to your MATLAB installation, and that the command works when entered in the terminal.
- If double-clicking opens MATLAB but not the specific file, MATLAB's desktop startup options may need to be adjusted or it could be a limitation of how MATLAB handles file opening arguments from the desktop environment.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.