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

조회 수: 2 (최근 30일)
Merse Gaspar
Merse Gaspar 2023년 9월 26일
답변: Voss 2023년 9월 26일
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?

채택된 답변

Voss
Voss 2023년 9월 26일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by