storing filenames from directory

조회 수: 9 (최근 30일)
Baba
Baba 2011년 11월 3일
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
Jan
Jan 2011년 11월 3일
Where do you get these filenames from?
Baba
Baba 2011년 11월 3일
i have them in my directory. .X stands for any extention

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 3일
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
Baba
Baba 2011년 11월 3일
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 2011년 11월 4일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by