在MATLAB中先前打开的m文件的历史记录 [英] History of previously opened m-files in MATLAB
问题描述
是否仍要在2个月或3个月前在MATLAB R2014b中查找以前打开的m文件的历史记录? (文件和路径的名称列表)
Is anyway to find history of previously opened m-files in MATLAB R2014b from 2 or 3 months ago? (a list of name of files and paths)
推荐答案
Matlab R2014b将其最近的文件存储在以下位置:
Matlab R2014b stores its recent files in:
%APPDATA%\MathWorks\MATLAB\R2014b\MATLAB_Editor_State.xml
这是一个.xml
文件,因此可以很容易地使用xmlread
进行加载和解析.我对xml解析语法不是很熟悉,但是这里是如何获取有关文件的信息(当然要适应您的需求):
It's a .xml
file so it's easy to load and parse with xmlread
. I'm not very familiar with xml parsing syntax, but here is how to get information about files (to be adapted to your needs of course):
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.*
中键入,但似乎与最新文件无关(无论如何,有很多有趣的事情可以从命令行操作编辑器)
NB: I've tried to type in matlab command window matlab.desktop.editor.*
, but seems there's nothing regarding recent files (anyway there are a lot of interesting things to manipulate the editor from the command line)
这篇关于在MATLAB中先前打开的m文件的历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!