Filter löschen
Filter löschen

How to fprintf(or just print) fileparts

1 Ansicht (letzte 30 Tage)
yc j
yc j am 26 Jan. 2016
Kommentiert: yc j am 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?

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by