comparing between two string cells without using loops

3 ビュー (過去 30 日間)
daniel zayed
daniel zayed 2017 年 12 月 30 日
コメント済み: daniel zayed 2017 年 12 月 30 日
given 2 string cells and k categories how can i compare 2 string cells element by element without using loops.
for example: categories=sports,science,politics.
A=['sports','science','sports','politics']
B=['science','science','politics','politics']
the result have to be :
res=2 or:
res=[0,1,0,1]
anyone can help me with this , thank you .
  1 件のコメント
the cyclist
the cyclist 2017 年 12 月 30 日
The way you have defined A here, it will be the character array
A = 'sportssciencesportspolitics'
Do you actually mean that it is a cell array, defined as
A={'sports','science','sports','politics'}
??
(Notice that I used curly brackets where you used square brackets.) Or something else?

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2017 年 12 月 30 日
If you meant the cell array as I wrote it above, you can do
res = strcmp(A,B);
  1 件のコメント
daniel zayed
daniel zayed 2017 年 12 月 30 日
it is acell not charcter array, thx !!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by