Sunday, March 14, 2010

Matlab的regexp

給未來的裕翔

剛在Matlab裡看到一個regexp的用法

對這樣的字串 變數
options.tvregparam='
TV regularization parameter: 3.000000'

regexp(options.tvregparam,'\d')
會回傳所有是數字的index(3和0中間的小數點的位置則不回傳)
30    32    33    34    35    36    37

options.tvregparam(regexp(options.tvregparam ,'\d'))
回傳由上面位置所組成的字串
3000000


最後再一個str2num就可以把字串3000000變數字3000000


No comments:

Post a Comment