use part of file name

조회 수: 3 (최근 30일)
Baba
Baba 2012년 5월 31일
I have a directory with files in following format AAA_100_0.dat, AAA_100_1.dat, AAA_100_2.dat, and so on
Id like to be able to pull off parts of the file names for instance the number between two underscores which is 100 in this case, and the numbers between underscore and period, which increment in this case.
Thank you

답변 (2개)

per isakson
per isakson 2012년 5월 31일
sad = dir('AAA*.dat');
name_list = { sad.name };
captures the file names
cac = regexp( name_list, 'AAA_(\d+)_(\d+)\.dat', 'tokens' );
should (I have not tested) extract the numbers

Andrei Bobrov
Andrei Bobrov 2012년 5월 31일
fls = dir('AAA*.dat')
fn = {fls.name}
c = regexp(fn, '\d*', 'match' )
out = str2double(cat(1,c{:}))

카테고리

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