Compare two cell in Matlab.

652 views (last 30 days)
C Zeng
C Zeng on 14 Apr 2015
Commented: Star Strider on 15 Apr 2015
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
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?

Accepted Answer

Star Strider
Star Strider on 14 Apr 2015
To cast your array as cells, use curly brackets ‘{}’ rather than square brackets ‘[]’.
With that change:
A={'ddd', 'aaa'};
temp = strcmpi(A,B)
temp =
1 0
as desired.
Star Strider
Star Strider on 15 Apr 2015
My pleasure!

Sign in to comment.

More Answers (0)


Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!