无论如何,从2个月或3个月前在MATLAB R2014b中找到以前打开的m文件的历史记录? (文件和路径名称列表)
答案 0 :(得分:9)
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
注意:我尝试输入matlab命令窗口matlab.desktop.editor.*
,但似乎没有关于最近的文件(无论如何,从命令行操作编辑器有很多有趣的事情)< / em>的
答案 1 :(得分:2)
最后回答waIs真有帮助。我刚修改它以阅读并打开最近的标签文件。这适用于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
答案 2 :(得分:2)
基于CitizenInsane的答案,但适用于任何Matlab版本。
要找到任何Matlab版本的.xml
文件,请使用prefdir
:
>> prefdir
ans = '/Users/user/Library/Application Support/MathWorks/MATLAB/R2018a'
MATLAB_Editor_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
答案 3 :(得分:0)
在R2018b中,您可以在Most recently used file list
中增加Preferences > Editor/Debugger
。我喜欢上面的方法,但是如果您跨机器工作(例如,使用Github),则它们将不起作用。 I coded a solution使用来自计算机的修改文件日期,而不是依赖MATLAB本身。