Find indexes in cell array

13 Ansichten (letzte 30 Tage)
Davide Bordin
Davide Bordin am 10 Mai 2022
Kommentiert: Jon am 13 Mai 2022
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

Akzeptierte Antwort

Jon
Jon am 10 Mai 2022
Bearbeitet: Jon am 10 Mai 2022
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 Kommentare
Davide Bordin
Davide Bordin am 13 Mai 2022
thank you
Jon
Jon am 13 Mai 2022
Glad that it helped, good luck with your project

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by