Filter löschen
Filter löschen

storing filenames from directory

9 Ansichten (letzte 30 Tage)
Baba
Baba am 3 Nov. 2011
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 Kommentare
Jan
Jan am 3 Nov. 2011
Where do you get these filenames from?
Baba
Baba am 3 Nov. 2011
i have them in my directory. .X stands for any extention

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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 Kommentare
Baba
Baba am 3 Nov. 2011
if I wanted to just keep the part between _ and. (1200,1201,1202) would I need to convert? i tried -*. and that didn't work
Walter Roberson
Walter Roberson am 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by