How to set MATLAB R2015a as the default program for opening mfiles?

1

I have Mathematica 10.2 and MATLAB R2015a installed on my computer and unfortunately MATLAB m-files are recognized as Mathematica notebooks by the window.
When I right-click on an m-file and choose open with, there's no option for MATLAB. And if I use the option choose default program... from that context menu, click on Browse and go through the following path:

C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\matlab.exe   

It won't be added to the context menu. What can I do to solve the problem?

Sepideh Abadpour

Posted 2016-04-11T11:50:49.660

Reputation: 273

Did you tick "Always use this program"? – AFH – 2016-04-11T11:53:58.503

@AFH yes i did it – Sepideh Abadpour – 2016-04-11T12:01:05.553

I can't be sure that W7 was the same, but on W10, if you right-click one of the files you want to link then select Properties, the General tab shows the program which opens it with a Change button alongside: this will allow you to select the default program. – AFH – 2016-04-11T12:26:58.427

@AFH yes, there is such option in win7, too but as you see in the picture, MATLAB is not listed and if I click the Browse button and go through the path that I mentioned above to matlab.exe, it won't be added to the list and I cannot choose it

– Sepideh Abadpour – 2016-04-11T12:37:55.240

That is very strange. All I can suggest is to run explorer as administrator or to make sure that your internet security software has not locked your settings. – AFH – 2016-04-11T12:42:43.917

@AFH windows explorer? how can I find out if the internet security software has blocked the settings? I use Microsoft Security Essentials – Sepideh Abadpour – 2016-04-11T13:08:09.157

1I have not used MSE much, and I no longer have a system running it, but I would suggest you check the logs first, to see if there were any entries associated with your attempted change. If running explorer as administrator doesn't work and you can't find anything in MSE, then you may have to resort to regedit, but I don't recommend this if you've never used it before: the modifications necessary will depend on existing entries, so it will be difficult to give guidance, and mistakes could damage your system. – AFH – 2016-04-11T13:52:58.660

@AFH I've edited my question. Can you please have a look at it? – Sepideh Abadpour – 2016-04-12T04:58:08.023

1Try the following commands in a cmd shell: FTYPE matlabfile="C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\matlab.exe" "%1" followed by ASSOC .m=matlabfile. You should then be able to double-click a .m file and open it in matlab. – DavidPostill – 2016-04-12T11:00:20.743

@DavidPostill - Thanks for that comment: I knew about these commands, but I thought their scope was limited to typing file names in cmd shells. When I experimented I got errors if cmd was not run as administrator, but the associations then worked in explorer. It would be a good idea to type assoc .m first, so that the original association can be verified as .m=m-file, allowing it to be restored in the future if necessary. – AFH – 2016-04-12T12:18:24.720

@DavidPostill ok, it's fixed. in fact when I run the cmd as administrator and typed what you said matlab will be listed in the open with window and I can change the default program – Sepideh Abadpour – 2016-04-12T15:39:22.950

@AFH see my last comment – Sepideh Abadpour – 2016-04-12T15:39:45.687

1@sepideh Great. I will add an answer ;) – DavidPostill – 2016-04-12T15:40:10.467

Answers

1

How Can I set MATLAB as the default program for opening .m files?

You need to run the following commands as an Administrator in a cmd shell:

assoc .m 

Run this first, so that the original association can be verified as .m=m-file, allowing it to be restored in the future if necessary.

Then run:

ftype matlabfile="C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\matlab.exe" "%1" 
assoc .m=matlabfile

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • assoc - Display or change the association between a file extension and a fileType
  • ftype - Display or change the link between a FileType and an executable program.

DavidPostill

Posted 2016-04-11T11:50:49.660

Reputation: 118 938