matlab strfind用法,findstr和strfind区别
matlab中這兩個字符串查找的函數(shù)findstr(), strfind()表明上看起來用法相似,效果也相似。
一. findstr(s1,s2)--在較長的字符串中查找較短的字符串出現(xiàn)的次數(shù),并返回其位置,因此無論s1,s2哪個為長字符串,位置在前在后都沒有關(guān)系。
例:
s = 'Find the starting indices of the shorter string.';
findstr(s, 'the')
ans = 6 30
findstr('the', s)
ans = 6 30
二. strfind(s1,s2)--or strfind(s1,pattern),因此其意思在s1中搜索pattern。
例:
S = 'Find the starting indices of the pattern string';
strfind(S, 'in')
ans = 2 15 19 45
strfind(S, 'In')
ans = []
注意,第一個函數(shù)findstr函數(shù)中,不能識別元胞數(shù)組,該函數(shù)只能用于字符串中。而第二個函數(shù)strfind中,S可以是元胞數(shù)組格式的字符串。
通過cell2mat()可以把cell結(jié)構(gòu)轉(zhuǎn)成數(shù)據(jù),findstr(),strfind()函數(shù)只能對一維字符串?dāng)?shù)據(jù)進行操作,若是二維字符串則得使用別的函數(shù)。
總結(jié)
以上是生活随笔為你收集整理的matlab strfind用法,findstr和strfind区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php排斥ajaxsubmit函数,关于
- 下一篇: 11. Android框架和工具之 Lo