storing filenames from directory
12 views (last 30 days)
Show older comments
I would like to store filenames from a directory in a matrix. Filenames are of the following format:
11_1200.12.X
11_1201.37.X
11_1202.67.X
...
2 Comments
Accepted Answer
Walter Roberson
on 3 Nov 2011
fileinfo = dir('*.X');
fnames = {fileinfo.name};
Now fnames{1}, fnames{2} and so on will be the file names.
Note: the list will not necessarily be sorted. Use sort({fileinfo.name}) if you need it sorted.
2 Comments
Walter Roberson
on 4 Nov 2011
namepart = cellfun(@(S) S(4:7), fnames, 'Uniform', 0);
If you prefer it in numeric form, you can use
namepart = cellfun(@(S) str2double(S(4:7)), fnames);
More Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!