필터 지우기
필터 지우기

ismember for string matrix

조회 수: 63 (최근 30일)
Sam
Sam 2014년 11월 26일
댓글: Sean de Wolski 2014년 11월 26일
I have two string matrices;
A=['c1' 'c ' 'b ' 'd9']'; %UNIQUELIST
B=['d9' 'c1']'; %ORIGINALLIST
I would like do find member of B in A, using:
[LIA,LOCB]=ismember(A,B);
and it returns
LOCB =
3
4
3
0
0
0
1
2
But I actually would like it to return matching row index like this:
LOCB =
2
0
0
1
Thanks for your help
Sam

답변 (2개)

Sean de Wolski
Sean de Wolski 2014년 11월 26일
You need to make A and B cell arrays so that each string piece is a separate element (rather than a 1xn string. The fix is simple use {} instead of []
A={'c1' 'c ' 'b ' 'd9'}';
B={'d9' 'c1'}'
[LIA,LOCB]=ismember(A,B)
  댓글 수: 1
Sam
Sam 2014년 11월 26일
that hit the nail on the head, thanks!

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


dpb
dpb 2014년 11월 26일
You've got string arrays here; use the 'rows' optional argument to treat them as such instead of as individual characters...
>> [~,loc]=ismember(A,B,'rows')
loc =
2
0
0
1
>>
  댓글 수: 3
dpb
dpb 2014년 11월 26일
Did you try it and see???
Sean de Wolski
Sean de Wolski 2014년 11월 26일
Probably, but converting to cells is heavier weight if you don't need them for other things.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by