Borrar filtros
Borrar filtros

Locating number from file name

4 visualizaciones (últimos 30 días)
D F
D F el 28 de Mzo. de 2018
Comentada: Star Strider el 28 de Mzo. de 2018
I have file names 'Shot 12 Spectra data.mat' (many files where just the number varies). I want to select just the number from the file name. How do I do this please?

Respuesta aceptada

Star Strider
Star Strider el 28 de Mzo. de 2018
Editada: Star Strider el 28 de Mzo. de 2018
Try this:
str = 'Shot 12 Spectra data.mat';
Nr = sscanf(str, '%*s%d')
Nr =
12
EDIT
If the file names are in a cell array:
cel = {'Shot 12 Spectra data.mat'; 'Shot 13 Spectra data.mat'};
Nr = cellfun(@(x)sscanf(x, '%*s%d'), cel)
Nr =
12
13
  2 comentarios
D F
D F el 28 de Mzo. de 2018
Thanks!
Star Strider
Star Strider el 28 de Mzo. de 2018
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps 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