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일

0 개 추천

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

Jörg
Jörg 2011년 9월 25일
I tried that. Unfortunately it only leads to ans=0. I'm using Matlab 2009a.
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개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2011년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by