Borrar filtros
Borrar filtros

How to fprintf(or just print) fileparts

1 visualización (últimos 30 días)
yc j
yc j el 26 de En. de 2016
Comentada: yc j el 26 de En. de 2016
man... I have read fileparts command, and i just can't do it... I am in a hurry right now..
I have files named such as 1.0 f.txt, 1.5 f.txt, 1.6 f.txt, 2.0 f.txt .... so on.
I want to fprintf or print only the numbers from the file name, such as 1.0, 1.5, 1.6, 2.0... so on.
I guess I have to use fileparts command, but don't quite understand how to separate the numbers, space, words, and extension..
Can anyone give me simple example or solution to this?

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de En. de 2016
If "filename" is the name of the file, then
parts = strsplit(filename, ' ');
and then parts{1} would be the string up to (but excluding) the space.
fprintf('The parameter value was: %s\n', parts{1})
  3 comentarios
Walter Roberson
Walter Roberson el 26 de En. de 2016
strsplit was added in R2013a. If you are using a MATLAB older than that then you need to indicate which version so that we can avoid wasting our time proposing solutions that cannot work for your version.
On the other hand,
idx = find(filename == ' ', 1, 'first');
part1 = filename(1:idx-1);
fprintf('The parameter value was: %s\n', part1);
yc j
yc j el 26 de En. de 2016
Thank you for the kind answers! means a lot to me!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings 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