转载:https://blog.csdn.net/yujiaerzong/article/details/77624167

  1. 将下面代码复制保存为 associateFiles.m 文件。
    或者从下面链接下载文件https://ww2.mathworks.cn/matlabcentral/fileexchange/51165-matlab-file-association-fix

  2. 在MATLAB中运行 associateFiles.m 文件,即在命令行中输入 associateFiles 然后 回车。

  3. 步骤2程序运行生成文件 MatlabFileAssocFix.reg 。

  4. 关闭MATLAB,双击运行 MatlabFileAssocFix.reg,会提示添加注册表信息,同意。

可以才去在bin目录中选择以管理员身份运行
MatlabFileAssocFix.reg文件就在matlab安装文件夹的bin目录中

  1. 设置.m文件默认打开程序为MATLAB2016a 完工。

function associateFiles(action, userExtList, fileStr)

% associateFiles(action, extList, fileStr)
%
% Makes a registry files that can be used to set correct file associantions on
% a windows platform. The following MATLAB file extensions are supported:
% .m, .mat, .fig, .mexw32, .mexw64, .p, .mdl, .mdlp, .slx, .mldatx, .req,
% .sldd, .slddc, .slxp, .sltx, .mn, .mu, .muphlp, .xvc, .xvz, .ssc, .mlapp,
% .mlappinstall, .mltbx, .mlpkginstall, .mlprj
%
% INPUT:
% action - optional string.
% * ‘add’ (default) adds/rewrites the MATLAB file association registry
% keys for this version.
% * ‘delete’ deletes the MATLAB file association registry entries for
% ALL versions of MATLAB (including “old style” ones)
% * ‘deleteadd’ is the same as ‘delete’ followed by ‘add’
% extList - optional string or cell array of strings containing the file
% extensions that should be associated with this version. Default is
% all MATLAB file extension (see above).
% fileStr - optional string with the name of the registry file to be written
% (possibly including path). Default is the file
% ‘MatlabFileAssocFix.reg’ in the current directory.
%
% USAGE:
% 1) Run with desired options (see above). A registry file should have been
% created.
% 2) Exit all running instances of MATLAB.
% 3) Make a backup copy of the windows registry if you need to restore the
% changes, see https://support.microsoft.com/en-us/kb/322756
% 4) Double click on the created file (possibly need to enter a password) and
% confirm.
% 5) Restart Windows (or explorer.exe).
% 6) The MATLAB files should now be associated with the MATLAB version that the
% registry file was created in and e.g. m-files should be opened in an
% already running instance of MATLAB.
%
% EXAMPLES:
% * associateFiles(‘deleteadd’) - Makes a registry files that deletes all
% previous MATLAB file association registry keys and write new ones that
% associates all MATLAB files with the MATLAB version that the registry file
% was created in.
% * associateFiles(’’, {’.m’, ‘.mat’, ‘.fig’}, ‘myFile’) - Makes a registry file
% “myFile.reg” that associates m-, mat- and fig-files with the MATLAB version
% that the registry file was created in.
%
% VERSION 1.0

% Defualt input
if (nargin < 1 || isempty(action))
action = ‘add’;
end
if (nargin < 2)
userExtList = {};
end
if (nargin < 3)
fileStr = ‘’;
end
if (~iscell(userExtList))
if (isempty(userExtList))
userExtList = {};
else
userExtList = {userExtList};
end
end

% Sanity check
if (~ischar(action) || (~strcmpi(action, ‘add’) && …
~strcmpi(action, ‘delete’) && ~strcmpi(action, ‘deleteadd’)))
error(‘The action to perform must be ‘‘add’’, ‘‘delete’’ or ‘‘deleteadd’’!’)
end
if (~isempty(userExtList) && ~min(cellfun(@ischar, userExtList)))
error(‘The file extension list must be a string or a cell array of strings!’)
end
if (~ischar(fileStr))
error(‘The file to write to must be a string!’)
end

% Get the currently running MATLAB version
verStr = regexp(version, ‘(\d*?.\d*?.\d*?).’, ‘tokens’);
verStr = verStr{1}{1};
verNum = str2double(regexprep(verStr, ‘(\d*?.\d*)[\x0000-\xffff]’, ‘$1’));
verHex = sprintf(‘x’, str2double(regexprep(verStr, …
'(\d
?).[\x0000-\xffff]’, ‘$1’)), str2double(regexprep(verStr, …
'\d
?.(\d*?).[\x0000-\xffff]*’, ‘$1’)));

% Get 32/64-bit
arch = computer;
switch arch
case ‘PCWIN’
binFolder = ‘win32’;
case ‘PCWIN64’
binFolder = ‘win64’;
end
binPath = fullfile(matlabroot, ‘bin’, binFolder);

% Known MATLAB files with possible DDE actions
fileExtCell = {…
‘fig’ , ‘MATLAB Figure’ , ‘-62’ , …
{‘Open’, ‘uiopen(’’%1’’,1)’} , [] ; …
‘m’ , ‘MATLAB Code’ , ‘-58’ , …
{‘Open’, ‘uiopen(’’%1’’,1)’} , {‘Run’, ‘run(’’%1’’)’} ; …
‘mat’ , ‘MATLAB Data’ , ‘-59’ , …
{‘Load’, ‘load(’’%1’’)’ } , {‘Open’, ‘uiimport(’’%1’’)’}; …
‘mdl’ , ‘Simulink Model’ , ‘-61’ , …
{‘Load’, ‘uiopen(’’%1’’,1)’} , [] ; …
‘mdlp’ , ‘Simulink Protected Model’ , ‘-72’ , …
[] , [] ; …
‘mexw32’, ‘MATLAB MEX’ , ‘-63’ , …
[] , [] ; …
‘mexw64’, ‘MATLAB MEX’ , ‘-63’ , …
[] , [] ; …
‘mn’ , ‘MuPAD Notebook’ , ‘-66’ , …
{‘Open’, ‘mupad(’’%1’’)’} , [] ; …
‘mu’ , ‘MuPAD Code’ , ‘-67’ , …
{‘Open’, ‘uiopen(’’%1’’,1)’} , [] ; …
‘muphlp’, ‘MuPAD Help’ , ‘-68’ , …
{‘Open’, ‘doc(symengine, ‘’%1’’)’} , [] ; …
‘p’ , ‘MATLAB P-code’ , ‘-60’ , …
[] , [] ; …
‘slx’ , ‘Simulink Model (SLX format)’, ‘-73’ , …
{‘Open’, ‘uiopen(’’%1’’,1)’} , [] ; …
‘ssc’ , ‘Simscape Model’ , ‘-65’ , …
{‘Open’, ‘uiopen(’’%1’’,1)’} , [] ; …
‘xvc’ , ‘MuPAD Graphics’ , ‘-69’ , …
{‘Open’, ‘mupad(’’%1’’)’} , [] ; …
‘xvz’ , ‘MuPAD Graphics’ , ‘-70’ , …
{‘Open’, ‘mupad(’’%1’’)’} , [] ; …
‘mlapp’ , ‘MATLAB Application’ , [] , [], [] ; …
‘mltbx’ , ‘MATLAB Toolbox’ , [] , [], [] ; …
‘mldatx’ , ‘Simulink Scenario’ , [] , [], [] ; …
‘req’ , ‘Simulink Requirements Link’ , [] , [], [] ; …
‘sldd’ , ‘Simulink Dictionary’ , [] , [], [] ; …
‘slddc’ , ‘Simulink Dictionary’ , [] , [], [] ; …
‘mlappinstall’, ‘MATLAB Application’ , [] , [], [] ; …
‘mlpkginstall’, ‘MATLAB Support Package’ , [] , [], [] ; …
‘slxp’ , ‘Simulink Protected Model Package’, [] , [], [] ; …
‘sltx’ , ‘Simulink Template’ , [] , [], [] ; …
‘mlprj’ , ‘MATLAB Project’ , [] , [], []};

% Possibly trim list
if (~isempty(userExtList))
fileExtCell = fileExtCell(ismember(fileExtCell(:, 1), …
regexprep(userExtList, ‘.’, ‘’)),

解决MATLAB不能设置为.m文件默认打开方式相关推荐

  1. Eclipse设置各类型文件默认打开方式

    如何修改Eclipse各类型文件的默认打开方式 工具/原料 Eclipse 方法/步骤 1 打开Eclipse,选择[window]-->[Preferences]打开设置 2 依次选择Gene ...

  2. win7错将.exe文件默认打开方式设置为记事本,如何修改?

    今天手残,把exe文件默认打开方式设置成了记事本,修改方法如下: 1.新建一个TXT文件,输入以下注册表信息: Windows Registry Editor Version 5.00[-HKEY_C ...

  3. ubuntu创建可执行图标、设置文件默认打开方式

    下面以在ubuntu上安装CAJVIewer为例进行介绍 1 准备工作 1.1 下载可执行程序 https://download.cnki.net/CAJViewer-x86_64-buildubun ...

  4. windows .exe 文件默认打开方式变成记事本的解决方法

    windows .exe 文件默认打开方式变成记事本的解决方法 如果cmd.exe打不开,先将默认打开方式切换成cmd.exe 如果用户选择了默认的模式,会在注册表中写一个UserChoice的注册信 ...

  5. 设置.ipynb文件默认打开方式为Jupyter Notebook

    设置.ipynb文件默认打开方式为Jupyter Notebook 设置双击直接打开.ipynb文件

  6. 设置Spyder为py文件默认打开方式

    设置Spyder为py文件默认打开方式 右键一个py文件 → 打开方式 → 选择其他应用,就会出现下面这个界面,把改选的都选上,然后查找其他应用. 然后找到你的spyder.exe,点打开就好了. 需 ...

  7. win7取消文件默认打开方式

    背景:选择了.sh文件默认打开方式为notepad++,这样需要执行的时候,双击不是执行而是打开文本了. 解决方法:删除注册表信息 其它文件类型操作一样 步骤一:打开运行小窗口,输入regedit命令 ...

  8. 通过Powershell修改文件默认打开方式

    修改原理 详情: Windows下通过注册表修改某个类型文件的默认打开方式和文件图标 脚本详情: Github:Change_default_programs.ps1 描述: 至少在Windows10 ...

  9. AIR管理文件关联, 指定文件默认打开方式

    参考:http://help.adobe.com/zh_CN/AIR/1.1/devappsflex/WS5b3ccc516d4fbf351e63e3d118676a5f3b-8000.html#WS ...

最新文章

  1. 在windows上解压linux文件夹,Win10如何使用命令行来解压缩文件?
  2. 第七章、Linux 文件与目录管理
  3. Reverse Linked List II
  4. 解决升级mac os X EI Capitan后遇到LibclangError: dlopen(libclang.dylib, 6): image not found.的问题...
  5. php base64尺寸,PHP base64编码的图像显示不正确
  6. shell中的变量与eval(转)
  7. 十二生肖swift1.2
  8. linux ifcfg-33 没有eth0解决方法
  9. 字符串+流+java_Java读取流并拼接转换成字符串
  10. Linux命令之shutdown
  11. jsp项目连接mysql_JSP程序使用JDBC连接MySQL的教程
  12. 老男孩python作业题_老男孩python学习第一天作业
  13. PCB Layout 设计流程
  14. 少儿编程语言有哪些分类,分别适合多大年龄的学生?
  15. 关于问答系统(QA)、对话系统(Chatbot)的学与思
  16. vue中prop验证、类型检查及注意事项
  17. 69、Android获取每日运动步数
  18. isFinite() 如果参数是 NaN,正无穷大或者负无穷大,会返回 false,其他返回 true
  19. 【NLP】第8章 将 Transformer 应用于法律和财务文件以进行 AI 文本摘要
  20. 菜鸟读财报,如何从上市公司财报中挖情报?--微博转载

热门文章

  1. NetBeans 7.4 Beta提示警告无效的异常处理
  2. Hamcrest Matchers,Guava谓词和Builder设计模式
  3. Java中的工厂方法模式
  4. Java中的方法调用有多昂贵
  5. Grails动态下拉菜单
  6. oracle中execute函数,oracle Execute Immediate(sql语句)
  7. IntelliJ IDEA for Mac 文件结构侧边窗口/类文件内部结构(File Structure)
  8. QPW 提现申请单表(暂时不做)(tf_cash_apply)
  9. java相除保留两位小数_Java:Java快速入门
  10. c语言动态内存分配数组,【C】动态内存分配