Effacer les filtres
Effacer les filtres

How to fprintf(or just print) fileparts

1 vue (au cours des 30 derniers jours)
yc j
yc j le 26 Jan 2016
Commenté : yc j le 26 Jan 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?

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Jan 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 commentaires
Walter Roberson
Walter Roberson le 26 Jan 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 le 26 Jan 2016
Thank you for the kind answers! means a lot to me!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by