MATLAB安装后的DOS框出现、脚本文件图标不显示、启动路径修改等问题解决

MATLAB安装方法

MATLAB是一款主要用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境,对于绝大多数从事科研及工程的人都是必不可少的一项开发工具。

目前全网关于MATLAB破解安装教程不少,这里给出一篇MATLAB R2020a的安装教程,但系统全面将破解安装后的一些小问题解决的文章不多。本文的写作目的主要针对的就是安装并破解后的一些小问题。之前解决的时候也是网络上到处搜罗,这里统一整理一下,给大家一个干净舒心的MATLAB使用体验,也方便我日后安装新版本的时候查看。

DOS框一闪而过问题

DOS框一闪而过问题说明

网上大多安装教程都是把bin文件夹下MATLAB快捷启动图标拖到桌面上,这样双击后确实可以启动MATLAB,但会出现一个一闪而过的DOS框。具体黑框的状况我就不截图了,大家可以尝试一下自行体会。然后这边给出某前辈的解释,大致意思就是拖到桌面的快捷方式定向到bin文件夹下,然后这个bin文件夹下的matlab starter application才真正定向到MATLAB的启动窗口。

DOS框一闪而过问题解决

主要的解决方法就是直接将bin/win64文件夹下的MATLAB应用程序以快捷启动的方式放到桌面,应用程序所在位置如下图所示(可能文件夹下的文件较多,要往下多拖一会儿鼠标才能找到)。
在这里插入图片描述
找到图标后右击-发送到-桌面快捷方式就完成啦,从桌面双击图标打开MATLAB时再也不会有黑框。

  • 额外说明:
    我这个是按照Windows系统是64位写的教程,如果你的电脑系统是32位的,那就应该是在bin/win32那个文件夹下发送相应的图标到桌面快捷方式。

脚本文件图标异常问题

MATLAB脚本文件图标异常说明

没用采用本方法修改注册表信息时,文件夹中的m文件是不会显示图标的,大致就是下图所示(原谅我盗了图,电脑上已经解决所以无原图):
在这里插入图片描述
同时,需要说明的一点是:没有采用该方法添加注册表信息的情况下,在文件夹中双击一个m文件时是会重新开一个MATLAB软件的。主要的原因就是没有把m文件关联到MATLAB,你双击m文件时系统无法正确处理这项文件。

脚本文件图标异常问题解决方法

新建一个m文件文本,复制下面的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 = {};
  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('%04x', 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, '\.', '')), :);
end
 
% Make registry file
if (~isempty(fileStr))
  % Possibly add file extension
  [~, ~, 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
% 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 numbers
  if (~strcmpi(fileExt, 'mexw64'))
    % Uses single DDE key for mex files
    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
  
  % New style keys with version number
  if (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']);
  end
  if (~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 file
  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
% 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};
  else
    PersistentHandler = '';
  end
  % DDE call
  ddeCall = 'ShellVerbs.Matlab';
  if (verNum > 8)
    % Changed from R2013a
    ddeCall = [ddeCall, '.', verStr];
  end
  % Default icon
  defIcon = 'm';
  if (~exist(fullfile(binPath, 'm.ico'), 'file'))
    defIcon = '';
  end
  % Path to MATLAB binary directory with \\
  binPathStr = regexprep(binPath, '\\', '\\\\');
  
  % Write Shell Open key
  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
  
  % Iterate over file types
  for fileExtNo = 1 : size(fileExtCell, 1)
    fileExt = fileExtCell{fileExtNo, 1};
    
    % File extension keys
    key  = ['[HKEY_CLASSES_ROOT\.', fileExt, ']%r@="MATLAB.', fileExt, '.', ...
      verStr, '"%r'];
    if (strcmpi(fileExt, 'm') && ~isempty(PersistentHandler))
      % Add some values
      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'];
    
    % DDE keys
    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
    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
    % Shell actions
    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
    
    % Explorer keys
    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}))
      % Add key
      key = [key, '[', explorerKey, '\.', fileExt, ...
        '\OpenWithList]%r"a"="MATLAB.exe"%r"MRUList"="a"%r%r'];
    else
      key = [key, '[', explorerKey, '\.', fileExt, '\OpenWithList]%r%r'];
    end
    % Write to file
    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
% Cloese file
fclose(fid);

运行完associateFiles.m文件后,会生成下图所示MatlabFileAssocFix.reg 文件。双击运行该文件,如果有软件阻拦的话需运行文件执行。

之后重启Matlab,任意选择一个.m文件,打开方式选择Matlab,设置成默认的。
在这里插入图片描述
上图中也可以看到associateFiles.m文件的图标显示是正确的。

参考:win10 Matlab2017a .m相关文件关联

MATLAB启动路径问题

MATLAB启动路径问题说明

其实完成上述两个步骤就已经可以愉快地使用MATLAB了,但方便大家可以在脚本文件存储上有一定的方便,还是建议大家执行下这一步骤——修改MATLAB启动时候的工作空间。

没有修改工作空间时MATLAB启动之后应该是在bin/win64文件夹下,这时候你新建的m文件如果保存的话是会放在该文件夹下的,下图给出工作空间样例图:
在这里插入图片描述
我用的MATLAB布局可能跟初始布局不太一样,这是我根据自己的喜好调整的,大家有自己的喜好就按自己的来即可。

不巧的是,该文件夹下都是MATLAB安装时产生的一些必要文件,自己编写的脚本文件如果放在该文件夹下的话极有可能会后续不易找到。此外,在完成一个比较大的课题,需要用到不少m文件时也不方便管理。因而作为一个使用时长4年的练习生,我的建议是新建一个专门放MATLAB代码的文件夹,专门用于放自己编写的MATLAB代码。

MATLAB启动路径问题解决

主要的操作就是修改 toolbox\local 文件夹下的 matlabrc.m 文件,只需在最后一行添加自己想前往的路径即可。

具体可以参考:修改Matlab启动时的默认工作空间

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值