How replace the duplicated row by the mean

2 vues (au cours des 30 derniers jours)
Mekala balaji
Mekala balaji le 18 Sep 2017
Commenté : Mekala balaji le 20 Sep 2017
Hi,
I have below data:
1.3
1.5
1.6
1.7
1.7
2.2
2.8
2.8
I want to find the row index of duplicate values (row4 & row5, row row7& row8) and replace these row by mean 1. row4&row5 replace by the average of them, similarly row7&row8
the final output is:
1.3
1.5
1.6
1.7
2.2
2.8
  2 commentaires
Guillaume
Guillaume le 18 Sep 2017
The mean of identical values is the same value. So isn't what you're after simply:
unique(yourvector, 'stable')
Cedric
Cedric le 18 Sep 2017
Do you have any question regarding my answer to your other question here? :

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 18 Sep 2017
Assuming that there is more to your question, and that your input is actually a matrix where one of the column has got the indexing values you mention:
[~, ~, group] = unique(yourmatrix(:, idcolumn), 'stable');
newmatrix = splitapply(@(rows) mean(rows, 1), yourmatrix, group)
  9 commentaires
Guillaume
Guillaume le 20 Sep 2017
Looks like unique didn't have the 'stable' option in 2010. Just remove it. The only difference is that your output matrix will be sorted according to your ID column. If that column is already sorted, it makes no difference.
Mekala balaji
Mekala balaji le 20 Sep 2017
Thanks, Sir, I tried in 2015 version and it works.

Connectez-vous pour commenter.

Plus de réponses (1)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by