Opening .m Files on Linux

34 visualizaciones (últimos 30 días)
Nicholas
Nicholas el 16 de Mzo. de 2024
Editada: JH Schue el 3 de Mayo de 2024
I am running Matlab 2021b with Ubuntu 20.04.3. I would like to be able to doubleclick .m files so that they automatically open in Matlab. The main problem is that right-clicking the file -> Properties -> Open With doesn't show Matlab as an application.

Respuestas (1)

Hassaan
Hassaan el 17 de Mzo. de 2024
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.
  1. Open a terminal (Ctrl+Alt+T).
  2. 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.
[Desktop Entry]
Type=Application
Name=MATLAB
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
Categories=Development;
Terminal=false
Save and close the editor (Ctrl+O, Enter, Ctrl+X).
2. Associate .m Files with MATLAB
  1. Still in the terminal, set MATLAB as the default application for .m files using the mime-type association.
mimeopen -d ~/example.m
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.
  6 comentarios
JH Schue
JH Schue el 3 de Mayo de 2024
btw, change
Exec=matlab -desktop
to
Exec=matlab -desktop -r "edit %f"
so it won't open an empty matlab editor
https://www.mathworks.com/matlabcentral/answers/794002-set-matlab-as-default-for-m-files-in-ubuntu-without-opening-an-empty-editor
JH Schue
JH Schue el 3 de Mayo de 2024
Editada: JH Schue el 3 de Mayo de 2024
If you have executed 'mimeopen -d ~/example.m', then Open With will show an application called 'usr', this is the true matlab editor... However, 'example.m' can not cover all .m file, now you can just right click any .m file and choose to Open With usr.
I have a matlab icon in Open With, but it never works, so I think it's just a bug of matlab. It points to a wrong path

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by