Comparing lists of strings
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
Azzi Abdelmalek
le 17 Nov 2012
Modifié(e) : Azzi Abdelmalek
le 17 Nov 2012
List_one='is smaller than'
List_two='they are both cell arrays'
idx=find(ismember(List_one,List_two))
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!