How to fprintf(or just print) fileparts

1 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2016-1-26
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 个评论
Walter Roberson
Walter Roberson 2016-1-26
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 2016-1-26
Thank you for the kind answers! means a lot to me!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by