필터 지우기
필터 지우기

Get the index for the search of multiple strings within an array of strings

조회 수: 11 (최근 30일)
Hi,
I have a (1x128) cell array like this: "list" = 'S01R' 'S02R' 'S03R'... etc And another short (1x16) cell array with the same type of characters, eg, "bad" = 'S01R' 'S02R' 'S03R'... etc
I want to know the index of my "list" where I may found the items listed in "bad", I'v tried regexp but this function only allow me to find single strings in my list, Also, I don't know how to get the index in a orderer list instead of a cell array like this c=[] [] [] [1] [] [] [] [] []
Thanks for any idea,
JL
  댓글 수: 1
Jan
Jan 2012년 7월 12일
Please post examples in valid Matlab code, such that they can be used directly in an answer by copy&paste.

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

채택된 답변

Jan
Jan 2012년 7월 12일
See FEX: CStrAinBP: Reply the indices of common strings.

추가 답변 (3개)

Ryan
Ryan 2012년 7월 12일
편집: Ryan 2012년 7월 12일
Is this what you were looking for?
list = {'bad','worse','good','okay'};
badlist = {'bad','worse'};
idx = ismember(list,badlist);
This returns:
idx = 1 1 0 0;
  댓글 수: 1
Dhruv Ghulati
Dhruv Ghulati 2015년 12월 21일
This works for exact text search, but not for if a string contains a particular set of characters. I find strfind() a better approach if you have that particular use case.

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


F.
F. 2012년 7월 12일
did you try "intersect" ???
[C,ia,ib] = intersect(A,B) example

JoseLuis
JoseLuis 2012년 7월 12일
Thanks to all for your answers, I found something that works, http://www.mathworks.com/matlabcentral/newsreader/view_thread/310652#846320
CStrAinBP it does make it too,
JL

카테고리

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