History of previously opened m files in MATLAB

In any case, to find the history of previously opened m files in MATLAB R2014b 2 or 3 months ago? (list of file names and paths)

+5
source share
4 answers

Matlab R2014b saves its latest files to:

%APPDATA%\MathWorks\MATLAB\R2014b\MATLAB_Editor_State.xml 

This is a .xml file, so it is easy to download and xmlread with xmlread . I'm not very good at xml parsing syntax, but here's how to get file information (to be tailored to your needs, of course):

 function [recentFiles] = GetRecentFiles() %[ % Opens editor 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 the following structure:

 recentFiles = 1x43 struct array with fields: AbsPath LastWrittenTime Name 

NB: I tried to enter the matlab command window matlab.desktop.editor.* , But there seemed to be nothing regarding the latest files (anyway, there are a lot of interesting things for controlling the editor from the command line)

+10
source

The last answer is really helpful. I just changed it to read and open the last tabs. This works on Matlab R2013a:

 function [recentFiles] = recover_tabs() %[ % Opens editor 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
source

In R2018b, you can enlarge the Most recently used file list in Preferences > Editor/Debugger . I like the methods described above, but they do not work if you work on different computers (for example, using Github). I encoded a solution that uses a modified file date from a machine, rather than relying on MATLAB itself.

0
source

The base is in CitizenInsane's answer, but for any version of Matlab.

To find the .xml file in any version of Matlab, use prefdir :

 >> prefdir ans = '/Users/user/Library/Application Support/MathWorks/MATLAB/R2018a' 

MATLAB_Editor_State.xml will be stored there. Therefore, the function will be:

 function [recentFiles] = GetRecentFiles() % Opens editor 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 
0
source

Source: https://habr.com/ru/post/1213962/


All Articles