1. 程式人生 > >matlab預設M檔案開啟

matlab預設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('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, '\.', '')), :);  
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, ']%
[email protected]
="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]%
[email protected]
="', 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, ... ']%
[email protected]
="', 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]%[email protected]="', 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}, ']%[email protected]="', ddePar{1}, '"%r%r']; key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ... '\Shell\', ddePar{1}, '\command]%[email protected]="\"', binPathStr, ... '\\matlab.exe\""%r%r']; key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ... '\Shell\', ddePar{1}, '\ddeexec]%[email protected]="', ddePar{2}, '"%r%r']; key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ... '\Shell\', ddePar{1},'\ddeexec\application]%[email protected]="', ... ddeCall, '"%r%r']; key = [key, '[HKEY_CLASSES_ROOT\MATLAB.', fileExt, '.' verStr, ... '\Shell\', ddePar{1},'\ddeexec\topic]%[email protected]="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);

相關推薦

matlab預設M檔案開啟

function associateFiles(action, userExtList, fileStr) % associateFiles(action, extList, fileStr) % % Makes a registry files that

MATLABM檔案、MEX檔案、MAT檔案是什麼 .如何開啟(直接滑鼠拖入相應區域)

.M檔案是儲存一段程式碼的檔案,類似於C語言中的一個函式體;   這也是MATLAB中最常見的檔案儲存格式之一 .MEX檔案是一種“可在matlab環境中呼叫的C(或fortran)語言衍生程式”。也就是說,MEX檔案的原始碼檔案是由C或Fortran語言編寫的,後經matlab編譯器處理而生成的二進

MatlabM檔案轉為P檔案和exe可執行檔案達到加密效果

在matlab中如果你的程式碼很重要,需要加密,目前我查到了兩種方法:一、生成p檔案;二、生成.exe檔案 matlab生成p檔案的方法很簡單,在command wondow裡面用 pcode yourfile.m 命令可以將M檔案轉化為對應的pcode檔案yourfile.p,據說是不會被反編

在Linux伺服器上,命令列下執行Matlab的.m檔案

1、採用shell工具例如xshell連線伺服器,鍵入 matlab ,或者含有matlab的相關命令,按照提示要求安裝Xmanager工具,只需官網下載,按說明安裝。 2、直接執行Matlab:$matlab,然後可以開啟matlab工具,根據xmanager工具可以在本地開啟matlab

matlab的.m檔案釋出為可執行程式.exe 時出現Test checkout of feature 'Compiler' failed.

當使用matlab編寫好一個功能時候,希望它能以exe形式釋出出去,那該怎麼做呢?實際上很簡單, 1、在命令視窗輸入ploytool 然後會出現 這時選擇第一個,應用編譯 2、這時會出現如下介面,其中如果所需打包的.m檔案還需要呼叫其他的.m檔案,在下面的"Addtion

MATLABM檔案的使用

執行方法: 使用matlab的時候,可以在“Command Window”內直接書寫matlab程式碼,也可以將程式碼儲存到M檔案中,然後執行該檔案。使用matlab主介面選單“File”->“

MATLABm檔案分節/Cell

今天看到大神的蟻群演算法程式碼,其中是一節一節的,劃分很清楚,如圖 點選任意一行,會將該行所在的節的背景顏色改變, Cell 原來這是使用了分節的手段,具體操作 選中MATLABm檔案編輯器

業餘01-MATLABM檔案雙擊沒反應修復方法

問題描述:Matlab的m檔案雙擊無反應,會跳出來選擇開啟該檔案應用程式的列表框,如圖1所示,選擇Matlab並不能開啟該檔案。但是通過MATLAB軟體的open可以開啟。 圖1  選擇matlab不能開啟m檔案 原因分析:要開啟非工作目錄下的檔案必須找到MATLA

MATLABM檔案關聯

function associateFiles(action, userExtList, fileStr) % associateFiles(action, extList, fileStr) % % Makes a registry files that can be

修改 centos的 ulimit預設數值--檔案開啟數量

由於專案需要,需要把定製的Centos系統 ulimit數值增大。增大的數值原想根據 OS檔案 /proc/sys/fs/file-max 檔案中的的數值作為 ulimit的值。 即 在 /etc/security/limits.conf 檔案中追加: echo *

MATLABM檔案的命名規則

1.M檔名不能與MATLAB的內部函式名相同。M檔名的命名最好是由大小寫英文字母/數字/下劃線等組成。如果出現相同MATLAB通常會提示。2. 檔名首字元不能是數字或下劃線。如果首字母是數字或者下劃線,MATLAB通常提示找不到該檔案。3.M檔名中不能有空格。若需要用兩個或以

python讀寫matlab的.m檔案

做深度學習的專案時,原始圖片一般會先轉換成其他格式,方便學習框架直接讀取,比如caffe的leveldb、lmdb,matlab的.m格式,tensorflow的tfrecords格式等。 python讀寫matlab的.m格式也很簡單,寫了小例子,直接上程式碼了 im

matlab中如何把m檔案預設開啟方式設成editor

可能是因為用了 ghost 恢復 Windows xp 系統,或者別的什麼原因,反正是雙擊開啟 .m 檔案時候,機器就開啟 matlab 程式,而不是像以前那樣在 matlab 程式的編輯器(matlab editor)裡開啟,這樣是很不方便。更鬱悶的是,如果本來已經打開了 matlab 程式,此時雙擊

解決MATLAB2016a不能設定為.m檔案預設開啟方式

1. 將下面程式碼複製儲存為 associateFiles.m 檔案。 2. 在MATLAB中執行 associateFiles.m 檔案,即在命令列中輸入 associateFiles 然後 回車。 3. 步驟2程式執行生成檔案 MatlabFileAssocFix.r

m檔案不能雙擊開啟,只能從matlab裡面開啟-解決辦法

方法一(借鑑): cwd=pwd; cd([matlabroot '\mcr\toolbox\matlab\winfun\private']); fileassoc('add',{'.m','.mat','.fig','.p','.mdl',['.' mexext]}); 

matlab2018安裝後,不關聯.m檔案,右鍵選擇matlab開啟會自動開啟一個空白matlab程式

step2:啟動matlab軟體step3:解壓,把資料夾裡的associateFiles.m檔案直接拖到matlab介面,matlab會出現一行run()程式碼,回車執行,資料夾會生成一個reg檔案,雙擊執行即可step4:重啟matlab,右鍵.m檔案選擇開啟方式matl

解決matlab安裝後沒有快捷方式啟動彈出DOS介面並且m檔案無關聯的方法

試了matlab的2011版和2013a兩個版本,預設安裝後都出現了以下問題: 桌面、開始選單無快捷方式 m檔案無圖示、未關聯 到安裝目錄啟動matlab時會閃現dos介面,啟動很慢 在開啟matlab後,雙擊m檔案仍會重新開啟一個matlab 解決方案

MATLAB入門學習-#5-M檔案MATLAB)程式基礎

MATLAB入門學習-#5-M檔案(MATLAB)程式基礎 1.was ist M檔案... 2.程式控制結構 3.函式檔案! 正式開始之前,先來兩個學習中學到的小TIP: 1.matlab程式中,中括號內容一般都是可以省略的東西。

學習筆記 matlab .m檔案 - 5

matlab之前一直是在命令視窗輸入命令,對於一些複雜的事,每次一條一條輸入,實在不方便,而且可重複性不高, 但是matlab提供了檔案方式,解決的這個問題 matlab檔案是一個字尾名為.M的檔案 ,如果PC不顯示字尾名,可以設定顯示,具體方法請自行網上搜索。 matlab可以執

hosts – 如何預設使用記事本開啟hosts檔案或快捷方式

注:本人只試過第一種方法!!! 做網站的同志們經常需要開啟hosts檔案修改解析來測試網站。 像小編一樣,我把hosts檔案直接做了個快捷方式在開始選單中。 遺憾的是,每次開啟都要選擇一下開啟方式,用記事本開啟,非常麻煩。 今天研究了下有幾種解決方法: 1、