gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 19:38:02 25 4
gpt4 key购买 nike

无论如何要查找 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

这会返回这样的结构:

recentFiles = 

1x43 struct array with fields:

AbsPath
LastWrittenTime
Name

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

关于以前在 MATLAB 中打开的 m 文件的历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28669347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com