如何用matlab提取字符串中的数字
1个回答
展开全部
S = REGEXP(STRING,EXPRESSION)
其中EXPRESSION的取法为:
. Any character
[] Any character contained within the brackets
[^] Any character not contained within the brackets
\w A word character [a-z_A-Z0-9]
\W Not a word character [^a-z_A-Z0-9]
\d A digit [0-9]
\D Not a digit [^0-9]
\s Whitespace [ \t\r\n\f\v]
\S Not whitespace [^ \t\r\n\f\v]
那么你的问题就可以使用下面的代码了
>>a='5000.xls'
a =
5000.xls
>> s=a(regexp(a,'\d'))
s =
5000
这时的s是字符型的,如果你需要数字的话就是用str2num转化一下
其中EXPRESSION的取法为:
. Any character
[] Any character contained within the brackets
[^] Any character not contained within the brackets
\w A word character [a-z_A-Z0-9]
\W Not a word character [^a-z_A-Z0-9]
\d A digit [0-9]
\D Not a digit [^0-9]
\s Whitespace [ \t\r\n\f\v]
\S Not whitespace [^ \t\r\n\f\v]
那么你的问题就可以使用下面的代码了
>>a='5000.xls'
a =
5000.xls
>> s=a(regexp(a,'\d'))
s =
5000
这时的s是字符型的,如果你需要数字的话就是用str2num转化一下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询