matlab提取string中的特定数字

a=
2012/1/4 9:15:57
2012/1/4 9:15:58
2012/1/4 9:15:58
2012/1/4 9:15:59
2012/1/4 9:15:59
2012/1/4 9:16:00
2012/1/4 9:16:00
2012/1/4 9:16:01

a为字符型的,如何提取分钟'15','16'...

即:str2num提取特定数字的具体格式是什么?

第1个回答  2013-07-28
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转化一下祝你学习愉快!
第2个回答  2013-07-28

你会正则表达式吗?提取两个冒号中间的字符即可

clear
clc
a=sprintf('2012/1/4 9:15:58\n2012/1/4 9:15:58\n2012/1/4 9:15:58\n2012/1/4 9:15:59\n2012/1/4 9:15:59\n2012/1/4 9:16:00\n2012/1/4 9:16:00\n2012/1/4 9:16:01')
b=str2num(char(regexp(a,'(?<=:)\d*(?=:)','match')))

追答

最后一句改为

time=str2num(char(regexp(sprintf('%s',txt'),'(?<=:)\d*(?=:)','match')))

追问

还是不行.. TT

追答

把Book3.xlsx发出来我看看

追问

http://pan.baidu.com/share/link?shareid=2943928465&uk=3205077189
麻烦了..

追答

晕,我电脑没装excel,matlab无法调用excel读取该文件,要不你把读出来的txt传给我看看

本回答被提问者采纳
相似回答