matlab 在cell中查找特定字符串


cell矩陣中字符的檢索不能直接使用等號,可以使用strcmp函數判斷兩個輸入字符串是否相等

1 c = strcmp( s1 , s2 )
2 if c == 1
3     s1 = s2
4 else
5     s1 ~= s2

使用find函數進行進一步檢索,得到cell中特征字符串的位置,find返回指定字符串的索引地址

 

idx = find( strcmp( cell , s ) //查找cell中字符串s的位置 , idx 表示一個矩陣
if isempty( idx ) 
    fprintf( 1 , '%s deesn't exsit in cell\n' , s );
else
    fprintf( 1 , ' find %s\ n' , s );

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM