2015-02-23 3 views
5

В любом случае, чтобы найти историю ранее открытых m-файлов в MATLAB R2014b от 2 или 3 месяцев назад? (Список названия файлов и путей)История ранее открытых m-файлов в MATLAB

+1

Это интересный вопрос. Я тоже хотел бы знать ответ на этот вопрос. – rayryeng

+2

Связано: [Восстановить более длинный список последних файлов из редактора Matlab] (http://stackoverflow.com/q/28587501/2586922) –

ответ

8

Matlab R2014b хранит последние файлы в:

%APPDATA%\MathWorks\MATLAB\R2014b\MATLAB_Editor_State.xml 

Это .xml файл так легко загружать и анализировать с xmlread. Я не очень хорошо знаком с синтаксисом XML разбора, но вот как получить информацию о файлах (адаптируются к вашим потребностям, конечно):

function [recentFiles] = GetRecentFiles() 
%[ 
    % Opens editor's state file 
    filepart = sprintf('MathWorks\\MATLAB\\R%s\\%s', version('-release'), 'MATLAB_Editor_State.xml'); 
    filename = fullfile(getenv('APPDATA'), filepart); 
    document = xmlread(filename); 

    % Get information about 'File' nodes 
    recentFiles = struct([]); 
    fileNodes = document.getElementsByTagName('File'); 
    for fni = 1:(fileNodes.getLength()) 

     attributes = fileNodes.item(fni-1).getAttributes(); % Careful, zero based indexing ! 

     for ai = 1:(attributes.getLength()) 

      % Get node attribute 
      name = char(attributes.item(ai-1).getName()); % Zero based + need marshaling COM 'string' type 
      value = char(attributes.item(ai-1).getValue()); % Zero based + need marshaling COM 'string' type 

      % Save in structure 
      name(1) = upper(name(1)); % Just because I prefer capital letter for field names ... 
      recentFiles(fni).(name) = value; 

     end 

    end  
%] 
end 

Это возвращает структуру, как это:

recentFiles = 

1x43 struct array with fields: 

    AbsPath 
    LastWrittenTime 
    Name 

NB: Я пытался ввести в командном окне MatLab matlab.desktop.editor.*, но, кажется, нет ничего относительно недавних файлов (во всяком случае есть много интересных вещей, чтобы манипулировать редактор из командной строки)

+0

Благодарим за ответ. Это последние 50 файлов, которые мы загрузили. Можем ли мы иметь историю со старыми файлами? – user2991243

+1

Я не думаю, что Matlab хранит бесконечную историю ... единственным решением будет просмотр последних файлов Windows (например, [Windows7] (http://www.itsupportguides.com/windows-7/windows-7-recent -items-folder-location /)) – CitizenInsane

2

Последний ответ wa действительно полезен. Я только что изменил его, чтобы читать и открывать последние вкладки. Это работает на Matlab R2013a:

function [recentFiles] = recover_tabs() 
%[ 
% Opens editor's state file 
filepart = sprintf('MathWorks\\MATLAB\\R%s\\%s', version('-release'), 'MATLAB_Editor_State.xml'); 
filename = fullfile(getenv('APPDATA'), filepart); 
document = xmlread(filename); 

% Get information about 'File' nodes 
recentFiles = struct([]); 
fileNodes = document.getElementsByTagName('File'); 
for fni = 1:(fileNodes.getLength()) 

    attributes = fileNodes.item(fni-1).getAttributes(); % Careful, zero based indexing ! 

    for ai = 1:(attributes.getLength()) 

     % Get node attribute 
     name = char(attributes.item(ai-1).getName()); % Zero based + need marshaling COM 'string' type 
     value = char(attributes.item(ai-1).getValue()); % Zero based + need marshaling COM 'string' type 

     % Save in structure 
     name(1) = upper(name(1)); % Just because I prefer capital letter for field names ... 
     recentFiles(fni).(name) = value; 

    end 

end  

%  loop to access files in the tab history 
for j=1:length(recentFiles) 
    arquivo = [recentFiles(j).AbsPath '\' recentFiles(j).Name]; 
%   if exists, then open 
    if exist(arquivo, 'file') == 2 
     open(arquivo); 
    end 
end 

%] 
end 
+0

Спасибо за это, помог мне восстановить мои открытые файлы .m – user3208430

Смежные вопросы