strmatch,matlab

2024-12-14 15:38:51
推荐回答(2个)
回答1:

两种用法:
str为字符串,strarray为字符串或是元胞数组
x = strmatch(str, strarray)
x = strmatch(str, strarray, 'exact')
第一种:比较str和strarray,看strarray中是否有str这个字符串,如果有,返回str在strarray中的位置(即数组下标),只要找到str就行,不需要严格相同
第二种区别在于要严格相同。
以下是两个例子:
x = strmatch('max', strvcat('max', 'minimax', 'maximum'))
返回 x= [1;3]

x = strmatch('max', strvcat('max', 'minimax', 'maximum'),'exact')
返回 x= 1

回答2:

Find possible matches for string
语法
x = strmatch('str', STRS)
x = strmatch('str', STRS, 'exact')
描述
x = strmatch('str', STRS) looks through the rows of the character array or cell array of strings STRS to find strings that begin with string str, returning the matching row indices. strmatch is fastest when STRS is a character array.
x = strmatch('str', STRS, 'exact') returns only the indices of the strings in STRS matching str exactly.
例子
The statement
x = strmatch('max', strvcat('max', 'minimax', 'maximum'))
returns x = [1; 3] since rows 1 and 3 begin with 'max'. The statement
x = strmatch('max', strvcat('max', 'minimax', 'maximum'),'exact')
returns x = 1, since only row 1 matches 'max' exactly.
这个是matlab 自带的help里面的,很权威,这英语你应该没问题吧