other than strcmp???

조회 수: 10 (최근 30일)
AZZA
AZZA 2011년 3월 14일
I am trying to use strcmp to compare 2 logical arrays, reading the notes, this cannot be used for logical arrays, only character arrays.
http://www.mathworks.com/help/techdoc/ref/strcmp.html
TF = strcmp(C1, C2)
As it stands i have 2 options, either:
1) find a function that will allow me to compare logical arrays.(No such look so far).
2) convert all the 1's to a specific letter and all my 0's to a different letter also, then i should be able to use strcmp. (But am unsure how to change specific data in an array.)
Regards
AZZA

답변 (3개)

Paulo Silva
Paulo Silva 2011년 3월 14일
a=logical([1 0 1 1])
b=logical([1 0 1 1])
isequal(a,b)
ans=
1
a=logical([1 0 1 1])
b=logical([1 0 0 1])
isequal(a,b)
ans=
0

Walter Roberson
Walter Roberson 2011년 3월 14일
You cannot successfully strcmp logical values for no particular reason I can see. The comparison just returns false.
You can, however,
strcmp(char(C1),char(C2))

AZZA
AZZA 2011년 3월 14일
Thanks for your answers guys, i have figured it out.
It is similar to what Paul Silva was getting at. So thank you both.
I used the following in the end:
C = A & B;
As this is a logic compare instruction. (Logic AND) Which also ensures C is the same size 32x32 matrix as the objects A and B that are being compared.
Cheers
AZZA
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 3월 14일
That approach will not work if A and B are not the same size, and it is unable to detect locations where one of the two has a 0 but the other has a 1.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by