String compare

10 Ansichten (letzte 30 Tage)
Jörg
Jörg am 25 Sep. 2011
Hi,
likely a beginners question. I have a matrix containing strings, say
A=['aa';'bb']
now I'm looking for a function f(x,string) that will do row-wise string comparison such that
f(A,'aa') leads to [1;0]
is that possible? I failed to use strcmp.
Thanks Jörg

Akzeptierte Antwort

Daniel Shub
Daniel Shub am 25 Sep. 2011
If you can use
A = {'aa'; 'bb'}
then
strcmp(A, 'aa')
works. The cell array for A might be better because it lets you have unequal length strings.
  3 Kommentare
Daniel Shub
Daniel Shub am 25 Sep. 2011
You tried it with a cell array?
Jörg
Jörg am 25 Sep. 2011
Ah, that did the trick. Thanks a lot!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by