String compare

조회 수: 11 (최근 30일)
Jörg
Jörg 2011년 9월 25일
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

채택된 답변

Daniel Shub
Daniel Shub 2011년 9월 25일
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
Daniel Shub
Daniel Shub 2011년 9월 25일
You tried it with a cell array?
Jörg
Jörg 2011년 9월 25일
Ah, that did the trick. Thanks a lot!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by