フィルターのクリア

How can I read in a number from a file name?

2 ビュー (過去 30 日間)
Jack Miskell
Jack Miskell 2015 年 11 月 18 日
コメント済み: Jack Miskell 2015 年 11 月 24 日
In my program the user selects a dicom file and I need to know a number that is contained within the file name.
For example, the file name could be "Image10_processed.dcm", and I want to take the 10 so I can use that to find the corresponding info in another file.
Is there a way that I can break the file name down and just take the number? I've looked elsewhere and there seems to be no simple solutions.
Any help is much appreciated.

採用された回答

Shruti Sapre
Shruti Sapre 2015 年 11 月 20 日
Hi Jack,
If you are storing the name of the file as a string, you can do something like this:
>>startIndex = sscanf(str, 'Image%d');
(I am assuming that the file name beings with "Image" here)
You could also use "regexp":
>>str='Image10_processed.dcm'
>>expression = '[0-9]';
>>str(startIndex)
Hope this helps!
-Shruti
  1 件のコメント
Jack Miskell
Jack Miskell 2015 年 11 月 24 日
Thank you for your help Shruti.
In the end I used regexp.
Thanks again!
Jack

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by