string comparison strcmp did not seem to work
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sam
am 14 Okt. 2014
Beantwortet: Guillaume
am 14 Okt. 2014
I have two identical string matrices (see attached MAT file) but dont know why strcmp below returns 0 while I was expecting one:
strcmp(PsName,PsNameReRef)
Thanks in advance for your help Sam
0 Kommentare
Akzeptierte Antwort
Guillaume
am 14 Okt. 2014
If you look at the ascii codes of both matrices:
double(PsName)
double(PsNameReRef)
You'll see where they differ. Your shorter string (GILBOA) is followed by two spaces (ASCII 32) in one and two NULL (ASCII 0) in the other. It's unfortunate that as char, they're displayed the same by matlab.
Another way to compare them, since they're the same size is
PsName == PsNameReRef
You immediately see which character differs.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!