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

21 ビュー (過去 30 日間)
JoseLuis 2012 年 7 月 12 日
コメント済み: Stephane 2020 年 2 月 2 日
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,
  1 件のコメント
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 2012 年 7 月 12 日
See FEX: CStrAinBP: Reply the indices of common strings.

その他の回答 (3 件)

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. 2012 年 7 月 12 日
did you try "intersect" ???
[C,ia,ib] = intersect(A,B) example
  1 件のコメント
Stephane 2020 年 2 月 2 日
thx for suggesting interstect for strings


JoseLuis 2012 年 7 月 12 日
Thanks to all for your answers, I found something that works,
CStrAinBP it does make it too,


Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by