MATLAB Answers

Why is a new instance of MATLAB opened when I double-click on a MATLAB file in Windows Explorer even if I have one instance of MATLAB already open on my Windows 7 machine?

314 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2013 年 4 月 18 日
コメント済み: Mitsu 2021 年 9 月 26 日 7:15
I have full administrative privileges on my Windows 7 machine and I run MATLAB as an administrator. I then open a Windows Explorer and double-click on a MATLAB file. I expect the MATLAB file to open in the existing instance of MATLAB, instead another instance of MATLAB is launched, and the MATLAB file opens there in the Editor. If I double-click on another MATLAB file in Windows Explorer, it opens in Editor in the second instance of MATLAB. However, if I close the second instance of MATLAB and then double-click on a MATLAB file in Windows Explorer it will open another MATLAB instance.
I am running MATLAB as an administrator because otherwise I cannot save path from File->Set Path->Save menu. I have User Control Access (UAC) turned on and I cannot turn it off because of security considerations.

採用された回答

MathWorks Support Team
MathWorks Support Team 2021 年 9 月 23 日 4:00
編集済み: MathWorks Support Team 2021 年 9 月 23 日 22:13
この 回答 は 1 人のコントリビューターによってフラグが設定されました
This behavior may have one of several causes:
A.
This may be a consequence of the security settings on Windows 7. When you run MATLAB as an administrator and then try to open a MATLAB file from Windows Explorer, you are not a privileged user as far as Windows Explorer is concerned. As a result, MATLAB that is open cannot open this MATLAB file since MATLAB is a program that is run by a privileged user (administrator).
To work around this issue, you can enable writing to the pathdef.m file. The pathdef.m file is located in the directory: 
MATLABROOT\toolbox\local
where MATLABROOT is the result of executing the following in the MATLAB command prompt:
matlabroot
To enable writing to pathdef.m:
  1. Open the directory with pathdef.m in the Windows Explorer, right-click on the file and open "Security" tab.
  2. Click the "Edit" button to modify permissions.
  3. Select the user or group that should be allowed to write to pathdef.m, i.e., Users.
  4. Check the "Write" check box and click "Apply"
If you have previously set MATLAB to be run as an administrator, change it to run it as an ordinary user. You will be now able to save path to the pathdef.m file and each time you click on the MATLAB file, if MATLAB is already open, MATLAB file will be opened in the Editor of the open MATLAB instance.
If this does not work, try associating the file with an older version of MATLAB, open the file and then change the association to the new version. This resolved the issue for a customer who was transitioning from R2017b to R2018a
B.
This issue may also arise if you uninstall an earlier release of MATLAB after installing a newer release. The newer release uses a different method to register file associations.
These associations are deleted from the registry when an older release is uninstalled. In this situation, please uninstall the new release and reinstall it.
If the file associations are not correct because you have manually registered the MATLAB file types with Windows Explorer, you can re-associate the MATLAB file types by following these instructions from the MATLAB documentation:
This page explains how to re-register the .MAT extension, but you can follow the same instructions for other file types.
  4 件のコメント
Nimish Sorathiya
Nimish Sorathiya 2018 年 10 月 9 日
Thank you so much... Solution B works!

サインインしてコメントする。

その他の回答 (5 件)

Shahram Bekhrad
Shahram Bekhrad 2016 年 5 月 30 日
Hello. I had the same problem on my win 8.1 and MATLAB but followed thorough with the suggested solution by MathWorks Support Team on top of the page and then followed by the other solution on MATLAB File Association Fix by Patrik Forssén on some other post in the site ( How to restore file association in Matlab 2015a for Windows ) and I think that it is alright now. Now when I double click on a MATLAB associated file IF I have an instance of MATLAB open, It opens the file directly in the editor or MATLAB file importer dialog (depends on the file) and if not it opens an instance of MATLAB and the rest follows.
  16 件のコメント
Mitsu
Mitsu 2021 年 9 月 26 日 7:15
Hello,
Does anyone know how to apply this solution to files opened from Windows PowerShell?
Whenever I open matlab script.m, it stills opens a new instance of MATLAB despite this fix.

サインインしてコメントする。


Azad Karatas
Azad Karatas 2018 年 1 月 26 日
Just download and run this program: https://www.mathworks.com/matlabcentral/fileexchange/51165-matlab-file-association-fix and double click the output reg file. Restart Matlab and it works.
  3 件のコメント
Sihong Xie
Sihong Xie 2021 年 7 月 5 日
It worked for me on Matlab 2019a.

サインインしてコメントする。


Farzaneh
Farzaneh 2014 年 8 月 20 日
I am using Matlab R2012b. I have the exact same problem, i.e. each time I want to open a matlab-related file, a new session of matlab is opened, instead of opening that file in the already opened matlab session. I have set full control permission to pathdef.m file. No success. Please help.
  2 件のコメント
Alex Jose
Alex Jose 2014 年 10 月 16 日
If you are a support customer, you can submit your question to MathWorks support via the 'My Service Requests' page which is accessible at http://www.mathworks.com/support.

サインインしてコメントする。


Behzad Vaferi
Behzad Vaferi 2020 年 8 月 20 日
Thank you very much.
It works on Matlab 2019b.
  1 件のコメント
Liqiang Zhang
Liqiang Zhang 2020 年 10 月 13 日
Which methods do you use to solve your problem? appreciate.

サインインしてコメントする。


Jorge Pesantez
Jorge Pesantez 2021 年 1 月 29 日
If you like me, are looking for a different problem but your browser took you here, I'll try to explain what my issue was and the easiest way of solving it.
My problem was that with a MATLAB new version (R2020b) for some reason my scripts were being opened on new windows every time.
Solution: on the new editor window that shows up when double-clicking the .m file, go to the circle with the down heading arrow on the top right, click on the arrow, and select Dock.
In case you are here for that silly issue, you're welcome. If don't, please go through these detailed and advanced solutions.
Cheers!

製品


リリース

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by