有相同的问题。这里是
解决方案,它在我的R2018b上运行良好。
在Matlab中运行此文件,它将生成.reg文件以修复问题(当然要运行它)。然后重新启动您的PC。
如果您无法(或不想)登录以下载文件,则可以查看该文件的代码:
function associateFiles(action, userExtList, fileStr)
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
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
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')));
arch = computer;
switch arch
case 'PCWIN'
binFolder = 'win32';
case 'PCWIN64'
binFolder = 'win64';
end
binPath = fullfile(matlabroot, 'bin', binFolder);
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' , [] , [], []};
if (~isempty(userExtList))
fileExtCell = fileExtCell(ismember(fileExtCell(:, 1), ...
regexprep(userExtList, '\.', '')), :);
end
if (~isempty(fileStr))
[~, ~, tmp] = fileparts(fileStr);
if (isempty(tmp))
fileStr = [fileStr, '.reg'];
end
fid = fopen(fileStr, 'w');
else
fid = fopen('MatlabFileAssocFix.reg', 'w');
end
if (fid == -1)
error('Failed to create registry file')
end
fprintf(fid, '%s\r\n\r\n', 'Windows Registry Editor Version 5.00');
fprintf(fid, '%s\r\n\r\n', ';FIXES MATLAB FILE ASSOCIATIONS');
explorerKey = ['HKEY_CURRENT_USER\Software\Microsoft\Windows\', ...
'CurrentVersion\Explorer\FileExts'];
for fileExtNo = 1 : size(fileExtCell, 1)
rmKeys = {};
fileExt = fileExtCell{fileExtNo, 1};
[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
if (~strcmpi(fileExt, 'mexw64'))
if (strcmpi(fileExt, 'mexw32'))
fileExtTmp = 'mex';
else
fileExtTmp = 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{:}];
end
end
if (strcmpi(action, 'add'))
[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f MATLAB.', ...
fileExt, '.', verStr ' /k']);
else
[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f MATLAB.', ...
fileExt, '. /k']);
end
if (~status)
keys = regexp(result, '(HKEY_CLASSES_ROOT[\x0000-\xffff]*?)\n', 'tokens');
rmKeys = [rmKeys, keys{:}];
end
[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
if (~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, ']']);
end
end
end
if (~strcmpi(action, 'delete'))
[status, result] = dos(...
'reg query HKEY_CLASSES_ROOT\.txt\PersistentHandler /ve');
if (~status)
PersistentHandler = regexp(result, '\{[\x0000-\xffff]*?\}', 'match');
PersistentHandler = PersistentHandler{1};
else
PersistentHandler = '';
end
ddeCall = 'ShellVerbs.Matlab';
if (verNum > 8)
ddeCall = [ddeCall, '.', verStr];
end
defIcon = 'm';
if (~exist(fullfile(binPath, 'm.ico'), 'file'))
defIcon = '';
end
binPathStr = regexprep(binPath, '\\', '\\\\');
key = ['[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
for fileExtNo = 1 : size(fileExtCell, 1)
fileExt = fileExtCell{fileExtNo, 1};
key = ['[HKEY_CLASSES_ROOT\.', fileExt, ']%r@="MATLAB.', fileExt, '.', ...
verStr, '"%r'];
if (strcmpi(fileExt, 'm') && ~isempty(PersistentHandler))
key = [key, '"Content Type"="text/plain"%r', ...
'"PerceivedType"="Text"%r'];
end
key = [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'];
end
key = [key, '[HKEY_CLASSES_ROOT\.', fileExt, ...
'\Versions\MATLAB.', fileExt, '.' verStr, ']%r"FileVersionMS"=dword:', ...
verHex, '%r"FileVersionLS"=dword:00000000%r%r'];
ddeData = 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'];
end
key = [key, '%r'];
icon = fileExt;
if (~exist(fullfile(binPath, [icon, '.ico']), 'file'))
icon = defIcon;
end
if (~isempty(icon))
key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ...
'\DefaultIcon]%r@="', binPathStr, '\\', icon, '.ico,0"%r%r'];
end
for shellActionNo = 4:5
ddePar = 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'];
end
end
key = [key, '[', explorerKey, '\.', fileExt, '\OpenWithProgids]%r'];
if (strcmpi(fileExt, 'm'))
key = [key, '"m_auto_file"=hex(0):%r'];
end
key = [key, '"MATLAB.', fileExt, '.', verStr, '"=hex(0):%r%r'];
if (~isempty(ddeData{4}))
key = [key, '[', explorerKey, '\.', fileExt, ...
'\OpenWithList]%r"a"="MATLAB.exe"%r"MRUList"="a"%r%r'];
else
key = [key, '[', explorerKey, '\.', fileExt, '\OpenWithList]%r%r'];
end
fprintf(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});
end
end
end
fclose(fid);