How to extract indices of matching strings in the following problem?

2 vues (au cours des 30 derniers jours)
Merse Gaspar
Merse Gaspar le 26 Sep 2023
Réponse apportée : Voss le 26 Sep 2023
Suppose I have an ordered string structure like this: {'word1','word2','word3','word4','word5','word6'.etc.}
And I have another one, which is a subset, for example {'word5','word2','word4'}.
And I want to extract indices corresponding to the first structure, so the result should be the ordered vector [5,2,4];
Which is the shortest solution for this, whithout a for cycle?

Réponse acceptée

Voss
Voss le 26 Sep 2023
big_list = {'word1','word2','word3','word4','word5','word6'};
small_list = {'word5','word2','word4'};
[~,idx] = ismember(small_list,big_list)
idx = 1×3
5 2 4

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by