How can I select specific text files ?

1 visualización (últimos 30 días)
Nicolas
Nicolas el 7 de Ag. de 2014
Comentada: Nicolas el 7 de Ag. de 2014
I have imported a bench of text file into MATLAB using
list_files2load = dir(fullfile(directory1,'Mod1*));
But then in those files (here is an example: Mod1-A-00k.txt, Mod1-A-10k.txt, Mod1-A-30k.txt; Mod1-B-00k.txt, Mod1-B-10k.txt, Mod1-B-30k.txt), I would like to pick only the ones that end with '*00k.txt'
how could I do that?
Thanks

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Ag. de 2014
Editada: Azzi Abdelmalek el 7 de Ag. de 2014
a={'Mod1-A-00k.txt', 'Mod1-A-10k.txt', 'Mod1-A-30k.txt', 'Mod1-B-00k.txt', 'Mod1-B-10k.txt', 'Mod1-B-30k.txt'}
idx=~cellfun(@isempty,regexp(a,'.+(?=00k.txt).+','match'))
b=a(idx)
%or
idx=~cellfun(@isempty,regexp(a,'.+(00k.txt)\>','match'))
b=a(idx)

Más respuestas (1)

Michael Haderlein
Michael Haderlein el 7 de Ag. de 2014
Just specify your dir query:
list_files2load = dir(fullfiles(directory1,'Mod1*00k.txt'));
  1 comentario
Nicolas
Nicolas el 7 de Ag. de 2014
that is good idea as well, didn't know I could do that ! selecting the '00k.txt' would be the first loop, then I would pick the '*10k.txt' and so on. So i think the answer of Azzi fits me better.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by