matlab中strcmp函式的使用

2021-07-31 04:26:07 字數 1082 閱讀 4894

strcmp是用於做字串比較的函式,按複雜程度及比較對像的不同主要可以分為以下三種情況:

1. tf=strcmp(s1,s2);

s1和s2是字串,比如:s1=『hello』,s2='matlab'。

如果s1和s2是一致的(identical),則返回值tf=1,否則,tf=0。

e.g.

>> s1='hello';

>> s2='hello';

>> s3='matlab';

>> tf1=strcmp(s1,s2);

>> tf1

tf1 =

1>> tf2=strcmp(s1,s3);

>> tf2

tf2 =

02. tf=strcmp(s,c);

s是乙個字串,the c is a cell array,c的元素全是字串,比如:s=『hello』,c=。

返回值tf是乙個和c有相同size的logical array,tf的元素是1或0。

把c中的每個元素和s做比較,如果一致,則tf對應位置的元素為1,否則,為0。

e.g.

>> s='hello';

>> c=;

>> tf=strcmp(s,c);

>> tf

tf =

1     0

0     0

3. tf=strcmp(c1,c1);

c1和c2都是cell arrays,並且它們具有相同的size,它們的元素都是字串,比如c1=;c2=;

返回值tf是乙個和c1或c2有相同size的logical array,tf的元素是1或0。

把c1和c2對應位置的元素做比較,如果一致,則tf對應位置的元素為1,否則,為0。

e.g.

>> c1=;

>> c2=;

>> tf=strcmp(c1,c2);

>> tf

tf =

1     1

0     0

matlab中strcmp函式的使用

matlab中strcmp函式的使用 strcmp是用於做字串比較的函式,按複雜程度及比較對像的不同主要可以分為以下三種情況 1.tf strcmp s1,s2 s1和s2是字串,比如 s1 hello s2 matlab 如果s1和s2是一致的 identical 則返回值tf 1,否則,tf 0...

matlab中strcmp函式的使用

strcmp是用於做字串比較的函式,按複雜程度及比較對像的不同主要可以分為以下三種情況 tf strcmp s1,s2 s1和s2是字串,比如 s1 hello s2 matlab 如果s1和s2是一致的 identical 則返回值tf 1,否則,tf 0。e.g.s1 hello s2 hell...

c sort函式 strcmp函式

sort函式 標頭檔案 algorithm 功能 排序 預設是公升序 如 b 100 sort b,b 100 可以自己定義cmp比較函式來決定sort函式的比較規則。include include include include using namespace std struct gg 1000...