matlab strfind用法,findstr和strfind区别
生活随笔
收集整理的這篇文章主要介紹了
matlab strfind用法,findstr和strfind区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
matlab中這兩個字符串查找的函數findstr(), strfind()表明上看起來用法相似,效果也相似。
一. findstr(s1,s2)--在較長的字符串中查找較短的字符串出現的次數,并返回其位置,因此無論s1,s2哪個為長字符串,位置在前在后都沒有關系。
例:
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 = []
注意,第一個函數findstr函數中,不能識別元胞數組,該函數只能用于字符串中。而第二個函數strfind中,S可以是元胞數組格式的字符串。
通過cell2mat()可以把cell結構轉成數據,findstr(),strfind()函數只能對一維字符串數據進行操作,若是二維字符串則得使用別的函數。
總結
以上是生活随笔為你收集整理的matlab strfind用法,findstr和strfind区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php排斥ajaxsubmit函数,关于
- 下一篇: 关联矩阵古林法的matlab代码,[转载