MATLAB与 *.m 文件关联
Matlab关联m文件
- 首先将以下代码复制到matlab中,然后保存到桌面上为associateFiles.m文件。
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 = {};elseuserExtList = {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('%04x', str2double(regexprep(verStr, ...'(\d*?)\.[\x0000-\xffff]*', '$1')), str2double(regexprep(verStr, ...'\d*?\.(\d*?)\.[\x0000-\xffff]*', '$1')));% Get 32/64-bit arch = computer; switch archcase '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, '\.', '')), :); end% Make registry file if (~isempty(fileStr))% Possibly add file extension[~, ~, tmp] = fileparts(fileStr);if (isempty(tmp))fileStr = [fileStr, '.reg'];endfid = fopen(fileStr, 'w'); elsefid = fopen('MatlabFileAssocFix.reg', 'w'); end if (fid == -1)error('Failed to create registry file') end % Write intial lines fprintf(fid, '%s\r\n\r\n', 'Windows Registry Editor Version 5.00'); fprintf(fid, '%s\r\n\r\n', ';FIXES MATLAB FILE ASSOCIATIONS');% REMOVE OLD KEYS explorerKey = ['HKEY_CURRENT_USER\Software\Microsoft\Windows\', ...'CurrentVersion\Explorer\FileExts']; % Iterate over file extensions for fileExtNo = 1 : size(fileExtCell, 1)rmKeys = {};fileExt = fileExtCell{fileExtNo, 1};% File extension keys[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f .', fileExt, ...' /k /e']);if (~status)keys = regexp(result, '(HKEY_CLASSES_ROOT[\x0000-\xffff]*?)\n', 'tokens');rmKeys = [rmKeys, keys{:}];end% Old style keys without version numbersif (~strcmpi(fileExt, 'mexw64'))% Uses single DDE key for mex filesif (strcmpi(fileExt, 'mexw32'))fileExtTmp = 'mex';elsefileExtTmp = fileExt;end[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f ', ...fileExtTmp, 'file /k /e']);if (~status)keys = regexp(result, '(HKEY_CLASSES_ROOT[\x0000-\xffff]*?)\n', ...'tokens');rmKeys = [rmKeys, keys{:}];endend% New style keys with version numberif (strcmpi(action, 'add'))% Only remove keys related to this version[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f MATLAB.', ...fileExt, '.', verStr ' /k']);else% Remove keys related to ALL version[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f MATLAB.', ...fileExt, '. /k']);endif (~status)keys = regexp(result, '(HKEY_CLASSES_ROOT[\x0000-\xffff]*?)\n', 'tokens');rmKeys = [rmKeys, keys{:}];end% Explorer keys[status, result] = dos(['reg query ', explorerKey, ' /f .', fileExt, ...' /k /e']);if (~status)keys = regexp(result, '(HKEY_CURRENT_USER[\x0000-\xffff]*?)\n', 'tokens');rmKeys = [rmKeys, keys{:}];end% Write to fileif (~isempty(rmKeys))fprintf(fid, '%s\r\n\r\n', [';REMOVES ', upper(fileExt), ...' FILE ASSOCIATIONS']);for keyNo = 1 : length(rmKeys)key = rmKeys{keyNo};fprintf(fid, '%s\r\n\r\n', ['[-', key, ']']);endend end% ADD KEYS if (~strcmpi(action, 'delete'))% Get text Persistent Handler[status, result] = dos(...'reg query HKEY_CLASSES_ROOT\.txt\PersistentHandler /ve');if (~status)PersistentHandler = regexp(result, '\{[\x0000-\xffff]*?\}', 'match');PersistentHandler = PersistentHandler{1};elsePersistentHandler = '';end% DDE callddeCall = 'ShellVerbs.Matlab';if (verNum > 8)% Changed from R2013addeCall = [ddeCall, '.', verStr];end% Default icondefIcon = 'm';if (~exist(fullfile(binPath, 'm.ico'), 'file'))defIcon = '';end% Path to MATLAB binary directory with \\binPathStr = regexprep(binPath, '\\', '\\\\');% Write Shell Open keykey = ['[HKEY_CLASSES_ROOT\Applications\MATLAB.exe\shell\open', ...'\command]%r', '@="\"', binPathStr, '\\MATLAB.exe\" \"%1\""%r%r'];fprintf(fid, '%s\r\n\r\n', ';ADD SHELL OPEN');lines = regexp(key, '([\x0000-\xffff]*?)%r', 'tokens');for lineNo = 1 : length(lines)fprintf(fid, '%s\r\n', lines{lineNo}{1});end% Iterate over file typesfor fileExtNo = 1 : size(fileExtCell, 1)fileExt = fileExtCell{fileExtNo, 1};% File extension keyskey = ['[HKEY_CLASSES_ROOT\.', fileExt, ']%r@="MATLAB.', fileExt, '.', ...verStr, '"%r'];if (strcmpi(fileExt, 'm') && ~isempty(PersistentHandler))% Add some valueskey = [key, '"Content Type"="text/plain"%r', ...'"PerceivedType"="Text"%r'];endkey = [key, '%r'];key = [key, '[HKEY_CLASSES_ROOT\.', fileExt, ...'\OpenWithProgids]%r"MATLAB.', fileExt, '.', verStr, '"=""%r%r'];if (strcmpi(fileExt, 'm') && ~isempty(PersistentHandler))key = [key, '[HKEY_CLASSES_ROOT\.', fileExt, ...'\PersistentHandler]%r@="', PersistentHandler, '"%r%r'];endkey = [key, '[HKEY_CLASSES_ROOT\.', fileExt, ...'\Versions\MATLAB.', fileExt, '.' verStr, ']%r"FileVersionMS"=dword:', ...verHex, '%r"FileVersionLS"=dword:00000000%r%r'];% DDE keysddeData = fileExtCell(ismember(fileExtCell(:, 1), fileExt), :);key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ...']%r@="', ddeData{2}, '"%r'];if (~isempty(ddeData{3}))key = [key, '"FriendlyTypeName"="@', binPathStr, '\\matlab.exe', ...',', ddeData{3}, '"%r'];endkey = [key, '%r'];% Iconicon = fileExt;if (~exist(fullfile(binPath, [icon, '.ico']), 'file'))icon = defIcon;endif (~isempty(icon))key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ...'\DefaultIcon]%r@="', binPathStr, '\\', icon, '.ico,0"%r%r'];end% Shell actionsfor shellActionNo = 4:5ddePar = ddeData{shellActionNo};if (~isempty(ddePar))key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ...'\Shell\', ddePar{1}, ']%r@="', ddePar{1}, '"%r%r'];key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ...'\Shell\', ddePar{1}, '\command]%r@="\"', binPathStr, ...'\\matlab.exe\""%r%r'];key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ...'\Shell\', ddePar{1}, '\ddeexec]%r@="', ddePar{2}, '"%r%r'];key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ...'\Shell\', ddePar{1},'\ddeexec\application]%r@="', ...ddeCall, '"%r%r'];key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ...'\Shell\', ddePar{1},'\ddeexec\topic]%r@="system"%r%r'];endend% Explorer keyskey = [key, '[', explorerKey, '\.', fileExt, '\OpenWithProgids]%r'];if (strcmpi(fileExt, 'm'))key = [key, '"m_auto_file"=hex(0):%r'];endkey = [key, '"MATLAB.', fileExt, '.', verStr, '"=hex(0):%r%r'];if (~isempty(ddeData{4}))% Add keykey = [key, '[', explorerKey, '\.', fileExt, ...'\OpenWithList]%r"a"="MATLAB.exe"%r"MRUList"="a"%r%r'];elsekey = [key, '[', explorerKey, '\.', fileExt, '\OpenWithList]%r%r'];end% Write to filefprintf(fid, '%s\r\n\r\n', [';ADD ', upper(fileExt), ...' FILE ASSOCIATIONS']);lines = regexp(key, '([\x0000-\xffff]*?)%r', 'tokens');for lineNo = 1 : length(lines)fprintf(fid, '%s\r\n', lines{lineNo}{1});endendend% Cloese file fclose(fid);
- 然后点击运行,会出现【MATLAB 编辑器】对话框,点击【更改文件夹】选项,运行即可。
- 这时会在自己桌面上出现【MatlabFileAssocFix.reg】文件,双击打开运行即可。
参考文章:Matlab软件与m文件无法关联的解决办法;
MATLAB与 *.m 文件关联相关推荐
- 如何恢复matlab关联,恢复matlab文件关联
安装matlab后,其应用程序starter在文件夹C:\Program Files\MATLAB\R2010b\bin中 重装系统后,若没动MATLAB安装目标,则MATLAB不用重新安装.(同样的 ...
- Matlab关联m文件与m文件关联设置
MATLAB安装后经常出现m文件不能关联到matlab打开,很烦恼.网上有一些设置教程,比如: 链接一 按照链接方式一方式二设置后出现报错. 修改注册表亦没用. 下面链接 链接二 链接三 链接四 都没 ...
- m文件关联matlab,matlab关联m文件
本文内容均摘抄自网络,备忘. 以管理员身份运行matlab 打开matlab的help窗口,找到MATLAB / User's Guide / Desktop Tools and Developmen ...
- MATLAB调用python文件方法
MATLAB是学术界最常用的编程工具,虽然MATLAB的功能已经很强大了,但是相对于开源的python来说,python丰富的开源工具和框架也是MATLAB所望尘莫及的.在编程实现任务所需的功能时,可 ...
- matlab编译器安装在哪里,MATLAB的m文件编辑器在哪里?
注意最新版的matlab,用右击.m文件打开然后查找文件关联到meditor.exe,你是找不到matlab安装程序下的编辑器程序的,而只能找到matlab.exe之类的无效关联.所以不如索性用hel ...
- MATLAB调用python文件以及调用.exe文件方法
引言: 在编程的时候有这么一个需求,就是要用MATLAB去调用python文件以及调用python写好的功能函数. 配置环境: MATLAB 2017b: python 2.7x: 方法: 1.查看m ...
- 如何将Matlab2019b和M文件关联
Matlab中关联M文件 Matlab是数学建模中一个常用的数据分析的软件,编写M脚本文件是对其进行处理的基本内容.对于刚刚安装的matlab软件,当你右键想要打开一个M文件,就会发现没有matlab ...
- matlab打开eps文件_如何在Windows上打开EPS图像文件
matlab打开eps文件 An EPS (Encapsulated PostScript) file is special type of image file containing a PostS ...
- 解决MATLAB2016b不能与M文件关联的问题
MATLAB2016b不能与M文件关联的解决方法 最近安装MATLAB 2016b之后,发现不能自动关联.m格式的文件.每次双击.文件都不能找到MATLAB打开,只能先打开MATLAB软件,然后再找到 ...
最新文章
- 字节跳动大佬的Python自学笔记.pdf
- schema类SpringMVC+Hibernate+Spring整合(二)
- 曹大带我学 Go(9)—— 开始积累自己的工具库
- 日期居然用字符串保存?我笑了
- 我从机器人先生那里了解到了有关InfoSec的全部信息
- 利用机器学习进行金融数据风险评估
- Java中的常量Constant
- [原创]利用DropDownlist来控制Textbox输入数字的精度
- 90后程序员健康现状:掉头发、油腻、腰椎间盘突出……
- 最详细win7下手动搭建PHP环境:apache2.4.23+php7.0.11
- python进度条先慢后快_tqdm学习-一个快速,可扩展的Python和CLI进度条
- 航天生物计算机新能源你对哪个领域的课,写作《语言简明》课件.ppt
- (四)语音识别测试案例
- my makefile 自动推导
- 指标公式c语言源码下载,通达信超级厉害指标公式源码附图-通达信公式-公式指标网...
- linux NVMe驱动总结
- LOL易游网络验证破解总结
- [高项]项目工作说明书VS采购工作说明书
- 如何免费申请js.org二级域名
- 支付宝支付-java-sdk