Find indexes in cell array

조회 수: 13 (최근 30일)
Davide Bordin
Davide Bordin 2022년 5월 10일
댓글: Jon 2022년 5월 13일
Hi all,
i have 2 arrays one containing all my values (even duplicates) and one containing the unique elements.
My goal is to find the index of my values based on the index of the unique elements
R = [2 ,1 , 1 , 2 , 4 , [1,3] , [1,3] , 4 , [1,3] , [2,5] , [2,5] , 4]
C= [2 , 1 , 4 , [1,3] , [2,5]]
Vectors [1,3] should be treated as 1 unique element, not as 1 and 3
If its easier we can work with letters
R1=['2B' , '1A' , '1A' , '2B' , '1D' , '1A+1C' ,'1A+1C' , '1D' , '1A+1C' , '1B+1E' , '1B+1E', '1D']
C1=['1A' , '2B' , '1A+1C' , '1D' , '1B+1E']
In both cases i expect to get an array
idx = [2, 1, 1, 2, 4, 3, 3, 4, 3, 5, 5, 4]
The order is important, idx should be in the same order of the original R/R1 vector.
I tried find and a bit of arrayfun but couldnt get it to work
Thank you so much in advance

채택된 답변

Jon
Jon 2022년 5월 10일
편집: Jon 2022년 5월 10일
R1={'2B' , '1A' , '1A' , '2B' , '1D' , '1A+1C' ,'1A+1C' , '1D' , '1A+1C' , '1B+1E' , '1B+1E', '1D'}
C1={'1A' , '2B' , '1A+1C' , '1D' , '1B+1E'}
[~,Locb] = ismember(R1,C1)
  댓글 수: 3
Davide Bordin
Davide Bordin 2022년 5월 13일
thank you
Jon
Jon 2022년 5월 13일
Glad that it helped, good luck with your project

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by