Effacer les filtres
Effacer les filtres

Repeating Values List Problemc

2 vues (au cours des 30 derniers jours)
Maxwell Barton
Maxwell Barton le 20 Déc 2019
Commenté : Maxwell Barton le 20 Déc 2019
I have two lists ix and iy, an example of which is shown below. I want to match any repeating values of ix with the corresponding points of iy and then average the points in iy. For example, [4 5 6] in iy all match with 12 in ix, so I would want to average [4,5,6] = 5, and replace all the duplicate 12s in ix with just a single 12, and replace [4 5 6] with 5. Is there a simple way to do this in MATLAB?
ix = [10 11 12 12 12]; iy = [2 3 4 5 6];
ixnew = [10 11 12]; iynew = [2 3 5];

Réponse acceptée

Stephen23
Stephen23 le 20 Déc 2019
Modifié(e) : Stephen23 le 20 Déc 2019
>> ix = [10,11,12,12,12];
>> iy = [2,3,4,5,6];
>> [ixnew,~,idx] = unique(ix(:),'stable');
>> iynew = accumarray(idx(:),iy(:),[],@mean)
iynew =
2
3
5
>> ixnew
ixnew =
10
11
12
  1 commentaire
Maxwell Barton
Maxwell Barton le 20 Déc 2019
Thanks a lot mate!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by