Defautl to open *.m files in MATLAB, linux

MATLAB R2020a, Ubuntu 20.04
I am trying to set MATLAB to open m files by default. MATLAB doesn't appear in the "Open with other Application" dialog.
This has been a problem in the past, but the solution doesn't work on modern Ubuntu.
I tried editing my defaults.list file by adding the line "text/m=matlab.desktop". This did not help.
Thanks for your answer.

 Réponse acceptée

Lukas Pospichal
Lukas Pospichal le 16 Juil 2020
Modifié(e) : Lukas Pospichal le 16 Juil 2020

1 vote

I had the same issue. I just now fixed it. In ubuntu 18.04. which I had previously I just installed the matlab application from the Ubuntu Software app. But in ubuntu 20.04 you need to use the Software app
And there install the package:
This will create the matlab.desktop file and from there you can just follow the instructions you linked (adding -r "edit %f" after the launch command). Hope this helps.

6 commentaires

Hank
Hank le 17 Juil 2020
Modifié(e) : Hank le 17 Juil 2020
I installed MATLAB using the .zip from mathworks.com. I wrote the following to matlab.desktop, so it would appear in the launcher.
[Desktop Entry]
Type=Application
Name=MATLAB R2020a
Icon=/home/<username>/.local/share/MATLAB/R2020a/bin/glnxa64/cef_resources/matlab_icon.png
Path=/home/<username>/Documents/MATLAB
Exec=/home/<username>/.local/share/MATLAB/R2020a/bin/glnxa64/MATLAB -desktop -prefersoftwareopengl
Terminal=false
Can you explain where to add r "edit %f" and how that tells ubuntu to open *.m with MATLAB.
I have a related problem. Maybe I should ask in a new thread, but:
MATLAB is trying to run an update. My MATLAB is installed for my user only in ~/.local . When I attempt to update, I get a permissions error. My user account doesn't have write permission to ~/.local/share/MATLAB/R2020a. I tried launching MATLAB with sudo matlab but this fails because my MATLAB license is tied to my username; it won't launch for user root. How can I update??
Thanks, H.
Lukas Pospichal
Lukas Pospichal le 18 Juil 2020
OK,
1) if you look at the package description that I included it tells you, the package does not include an installation of matlab. Instead it creates matlab.desktop for you (autmatically and correctly - but I'm not sure how it handels non-default installation directories) as well as it does some other magic to make sure MATLAB shows up in the open with context menu. Then you can just click on propperties and set MATLAB as default for any .m file.
2) If you are here and you can launch MATLAB just by double clicking a .m file. You will see that your MATLAB opens in your home directory and no script tab is open, only the commant line. So at this state you are forced to manually find the file you previously clicked inside matlab's "open file". This is where the <-r "edit %f"> comes in. It enables ubuntu passing arguments with MATLAB when launching it. Arguments, such as, the file you double clicked.
Lastly, the way I got it working was: Install MATLAB from .deb file using the Software app (not the Ubuntu Software app), used deafult installation path. Installed the MATLAB (community patch) package from the Software app, opened matlab.desktop and appended the <-r "edit %f"> at the end of "Exec=/..." line. Then restarted my machine.
Thanks, this worked for me very well to open .m files
.mat files, however, lead to the same nonsense in matlab as if it were opened with a text editor
Also trying to combine it with Filezilla (Let matlab view/edit the m files from there) does not seem to work
Paul Wright
Paul Wright le 6 Avr 2021
Two notes:
  1. The quotes are really important. Without them, MATLAB just opens an empty editor because the filename is parsed as a separate argument to MATLAB, rather than part of the command for MATLAB to run.
  2. Changing the .desktop file in this way makes MATLAB open with an empty editor window if you're just launching MATLAB directly from its icon. There must be a way to make the -r "edit %f" part conditional. I'm creating a separate question about that.
Paul Wright
Paul Wright le 6 Avr 2021
Uh-oh:
"Field codes must not be used inside a quoted argument, the result of field code expansion inside a quoted argument is undefined."
https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by