Extract number on variable name.

4 次查看(过去 30 天)
Laura
Laura 2016-7-19
My variable name is Final_50000_run_1
Is there a way to extract the number 50000 and 1 out.
Thanks.
  2 个评论
Matt J
Matt J 2016-7-19
Yes, there is, but how did those numbers get there in the first place?
Laura
Laura 2016-7-19
I saved it for different run of simulations in Fortran.

请先登录,再进行评论。

回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-7-19
编辑:Azzi Abdelmalek 2016-7-19
s='Final_50000_run_1'
regexp(s,'\d+','match','once')
If you want to extract all the numbers
regexp(s,'\d+','match')

Steven Lord
Steven Lord 2016-7-19
Is this a variable name or a file name? If it is a variable name, I recommend you read question 1 in the Programming section of the FAQ for an explanation of why including data in your variable names is discouraged. If it is a file name, see Azzi's answer.

类别

Help CenterFile Exchange 中查找有关 Fortran with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by