Comparing lists of strings
이전 댓글 표시
OK so I have two lists of, say, names, List_one and List_two.
- List_one is smaller than List_two: they are both cell arrays.
I want to find the indices where List_two contains elements from List_one. So far, I've been using strcmpi, but because the lists are different sizes (and in different orders) I need to do it element by element, which I can't believe is the most efficient solution. Any tips?
Just now I'm doing something like:
for i = 1:length(List_one) tf = strcmpi(List_one(i),List_two); ind = ind + tf; % so that the end result List_two(ind) = List_one. end
and I just can't imagine that's the best way, though I've spent a long time reading about ways to compare lists, I still haven't found anything satisfactory. One more, related, question:
If I have a list of names, and someone permutes it (they don't give me the indices for the new ordering, only the new list) - what is the best way to uncover the indices?
As in, List_two(indices) = List_two_permuted; - how do I find the permutation?
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2012년 11월 17일
편집: Azzi Abdelmalek
2012년 11월 17일
List_one='is smaller than'
List_two='they are both cell arrays'
idx=find(ismember(List_one,List_two))
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!