There is no single MATLAB command that will give you all the MATLAB related files in a directory and its subdirectories, but it is possible to process the
output of the GENPATH command to produce the desired result.
The MATLAB command GENPATH returns a string consisting of a folder and all its subfolders separated by the PATHSEP:
mkdir a
mkdir a\b
p = genpath('a')
produces the output:
Running REGEXP on p with the 'split' option produces a cell array of
the individual subdirectories:
s = regexp(p, pathsep, 'split')
which produces the output:
(Note that there is an empty string at the end because of that final trailing semicolon in p)
We can now loop through the cell array s and run the WHAT command on each folder:
for k=1:length(s)-1
what(s{k})
end
The file recursive_what.m combines the above steps into a MATLAB function.
Caveats: the 'split' option to REGEXP is new in 2007b.
You can get more information about GENPATH, PATHSEP and REGEXP from inside MATLAB by typing
or
or
or by going to the following URLs
Best Answer