以前在 MATLAB 中打开的 m 文件的历史记录
History of previously opened m-files in MATLAB
是否可以找到 2 或 3 个月前在 MATLAB R2014b 中打开的 m 文件的历史记录? (文件名和路径的列表)
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
这个returns一个像这样的结构:
recentFiles =
1x43 struct array with fields:
AbsPath
LastWrittenTime
Name
注意:我尝试输入 matlab 命令 window 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 中,您可以在 Preferences > Editor/Debugger
中增加 Most recently used file list
。我喜欢上面的方法,但如果你跨机器工作(例如,使用 Github),它们就不起作用了。 I coded a solution 使用来自机器的修改文件日期,而不是依赖 MATLAB 本身。
基于 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
是否可以找到 2 或 3 个月前在 MATLAB R2014b 中打开的 m 文件的历史记录? (文件名和路径的列表)
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
这个returns一个像这样的结构:
recentFiles =
1x43 struct array with fields:
AbsPath
LastWrittenTime
Name
注意:我尝试输入 matlab 命令 window 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 中,您可以在 Preferences > Editor/Debugger
中增加 Most recently used file list
。我喜欢上面的方法,但如果你跨机器工作(例如,使用 Github),它们就不起作用了。 I coded a solution 使用来自机器的修改文件日期,而不是依赖 MATLAB 本身。
基于 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