find ID's of repeated values in array
Mostra commenti meno recenti
Let's say I have 2 arrays, one longer t1 (1x15 double) and a shorter one t2(1x8 double) and I tried to find the indices of t1 in the t2 as follows:
t1=[1,2,3,3,3,4,5,6];
t2=[1,1.5,2,3,4,5,6,7,8,9,9.5,19,25,31,42];
IDt1_int2=ismember(t2,t1)
>> ismember(t2,1)
ans =
1×15 logical array
1 0 1 1 1 1 1 0 0 0 0 0 0 0 0
but what I acutally wanted is something like this
IDt1_int2=find(ismember(t2,t1));
find(ismember(t2,t1))
ans =
1 3 4 5 6 7
but what i want it to give as an ouput is an array of IDs which considers the numbeer 3 in my t1 three times like this
[1 3 4 4 4 5 6 7];
Could you help here? Thank you
2 Commenti
The simple MATLAB approach:
t1 = [1,2,3,3,3,4,5,6];
t2 = [1,1.5,2,3,4,5,6,7,8,9,9.5,19,25,31,42];
[~,idx] = ismember(t1,t2) % note the order!
Don't waste your time calling ISMEMBER multiple times in an inefficient loop.
Kim Arnold
il 17 Set 2021
Risposta accettata
Più risposte (1)
KSSV
il 17 Set 2021
[c,ia] = ismember(t2,t1)
2 Commenti
Kim Arnold
il 17 Set 2021
Modificato: Kim Arnold
il 17 Set 2021
Kim Arnold
il 17 Set 2021
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!