History 以前在MATLAB中打开的m文件的历史记录

History 以前在MATLAB中打开的m文件的历史记录,history,matlab,History,Matlab,不管怎样,是否要查找2或3个月前在MATLAB R2014b中打开的m文件的历史记录?(文件和路径的名称列表)Matlab R2014b将其最近的文件存储在: %APPDATA%\MathWorks\MATLAB\R2014b\MATLAB_Editor_State.xml 它是一个.xml文件,因此很容易用xmlread加载和解析。我不太熟悉xml解析语法,但下面是如何获取有关文件的信息(当然要适应您的需要): 这将返回如下结构: recentFiles = 1x43 struct ar

不管怎样,是否要查找2或3个月前在MATLAB R2014b中打开的m文件的历史记录?(文件和路径的名称列表)

Matlab R2014b将其最近的文件存储在:

%APPDATA%\MathWorks\MATLAB\R2014b\MATLAB_Editor_State.xml
它是一个
.xml
文件,因此很容易用
xmlread
加载和解析。我不太熟悉xml解析语法,但下面是如何获取有关文件的信息(当然要适应您的需要):

这将返回如下结构:

recentFiles = 

1x43 struct array with fields:

    AbsPath
    LastWrittenTime
    Name

注意:我试着在matlab命令窗口中键入matlab.desktop.editor.*,但似乎没有关于最近的文件的内容(无论如何,有很多有趣的东西可以从命令行操纵编辑器)

最后的答案真的很有帮助。我刚刚修改了它以读取和打开最近的选项卡文件。这适用于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

在R2018b中,您可以在
首选项>编辑器/调试器
中增加
最近使用的文件列表
。我喜欢上面的方法,但是如果您跨机器工作(例如,使用Github),它们就不起作用。它使用来自机器的修改过的文件数据,而不是依赖于MATLAB本身

citizensane回答中的Base,但适用于任何Matlab版本

要在任何Matlab版本中查找
.xml
文件,请使用
prefdir

>> prefdir

ans =  '/Users/user/Library/Application Support/MathWorks/MATLAB/R2018a'
MATLAB\u Editor\u State.xml
将存储在那里。因此,功能将是:

function [recentFiles] = GetRecentFiles()

% Opens editor's state file
filepart = sprintf([ prefdir '/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    

这是一个有趣的问题。我也想知道这个问题的答案。这是我们加载的最后50个文件。我们可以有一个旧文件的历史吗?我不认为Matlab有无限的历史。。。您唯一的解决方案是查看windows最近的文件(例如)。谢谢您的帮助,帮助我恢复打开的.m文件
function [recentFiles] = GetRecentFiles()

% Opens editor's state file
filepart = sprintf([ prefdir '/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