Compare two cell in Matlab.

293 ビュー (過去 30 日間)
C Zeng
C Zeng 2015 年 4 月 14 日
コメント済み: Star Strider 2015 年 4 月 15 日
Hello, I have a question that,
if A=[ 'ddd', 'aaa']; B=['ddd']; I want to return an array that compare whether A's cell is equivalent to B's content. (sorry I know it is not well written)
So it should be [1,0] where first cell is equivalent but second is not.
However, my code has a problem:
for j=1:Num
temp(j)=(A{j}==B{1});
end
that it returns a comparison of vector, for example temp(1)=[1 1 1]; How can I do a comparison and just return 1 or 0, not an array.
How can I do it vectorization?
Thanks.

採用された回答

Star Strider
Star Strider 2015 年 4 月 14 日
To cast your array as cells, use curly brackets ‘{}’ rather than square brackets ‘[]’.
With that change:
A={'ddd', 'aaa'};
B={'ddd'};
temp = strcmpi(A,B)
produces:
temp =
1 0
as desired.
  8 件のコメント
C Zeng
C Zeng 2015 年 4 月 15 日
Thanks Star!
Star Strider
Star Strider 2015 年 4 月 15 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by