matlab 获取字符串中的数字
str='1999.jpg'
A=isstrprop(str,'digit');
B=str(A);
C=str2num(B)
函数功能:
str2num:把字符串转换数值,可以使用str2double来替代str2num。在matlab命令窗口中键入doc str2num或help str2num即可获得该函数的帮助信息。
isstrprop:用于判断是否是数字,是则返回1
用正则表达式匹配吧:
>> s = '[数字一12000] [数字二28000]'
s =
[数字一12000] [数字二28000]
>> ms = regexp( s, '(?<=\w+)\d+', 'match' )
ms =
'12000' '28000'
然后将字符串转换为数字:
>> num1 = str2num( ms{ 1 } )
num1 =
12000
a='[数字一12000] [数字二28000]';
index1=strfind(a,'一');
index2=strfind(a,'二');
index3=strfind(a,']');
num1=a(index1+1:index3(1)-1)
num2=a(index2+1:index3(2)-1)
用正则表达式匹配吧:
>>
s
=
'[数字一12000]
[数字二28000]'
s
=
[数字一12000]
[数字二28000]
>>
ms
=
regexp(
s,
'(?<=\w+)\d+',
'match'
)
ms
=
'12000'
'28000'
然后将字符串转换为数字:
>>
num1
=
str2num(
ms{
1
}
)
num1
=
12000