Borrar filtros
Borrar filtros

Reading files in a specified order

3 visualizaciones (últimos 30 días)
L'O.G.
L'O.G. el 29 de Mzo. de 2022
Editada: Stephen23 el 29 de Mzo. de 2022
I have multiple files of the same type in a directory that all have the same beginning, say "A11_K", followed by a numbers specific to the file. For example
A11_K25-1.txt
A11_K25-2.txt
A11_K27-1.txt
I know I can read all of the files of that type using something like files = dir('A11_K*') but how do I make sure I read them, in the numeric order following the K above as in the example list?

Respuesta aceptada

Stephen23
Stephen23 el 29 de Mzo. de 2022
Editada: Stephen23 el 29 de Mzo. de 2022
Download NATSORTFILES here:
and use it like this:
S = dir('A11_K*.txt');
S = natsortfiles(S);

Más respuestas (1)

Fangjun Jiang
Fangjun Jiang el 29 de Mzo. de 2022
>> sort({'A11_K25-2.txt','A11_K27-1.txt','A11_K25-1.txt'})
ans =
1×3 cell array
{'A11_K25-1.txt'} {'A11_K25-2.txt'} {'A11_K27-1.txt'}

Categorías

Más información sobre Downloads en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by