Locating number from file name

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?

 採用された回答

Star Strider
Star Strider 2018 年 3 月 28 日
編集済み: Star Strider 2018 年 3 月 28 日

0 投票

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 件のコメント

D F
D F 2018 年 3 月 28 日
Thanks!
Star Strider
Star Strider 2018 年 3 月 28 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSpecialized Power Systems についてさらに検索

タグ

質問済み:

D F
2018 年 3 月 28 日

コメント済み:

2018 年 3 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by