Dynamic row select and calculate mean of selected row

I have some data like this.
1 0.0975 0.1576 0.14188
1 0.2784 0.9705 0.42176
2 0.5468 0.9571 0.91573
3 0.9575 0.4853 0.79220
3 0.9648 0.8002 0.95949
These are the elements of 5x4 matrix.I want to calculate the mean of all columns which have same value in row of first column. For instance In first column the first 3 rows are "1". Now I want to calculate mean of column 2, column3, column4 and column 5. The output is something like
1 0.1880 0.56410 0.2818
2 0.5468 0.95716 0.9157
3 0.9611 0.64282 0.8758
I have more than 5000 rows like this. I will be really thankful to all of you guys.

 Réponse acceptée

Do you have the Statistics Toolbox? If so, you can use the grpstats command:
x = [1 0.0975 0.1576 0.14188
1 0.2784 0.9705 0.42176
2 0.5468 0.9571 0.91573
3 0.9575 0.4853 0.79220
3 0.9648 0.8002 0.95949];
groupMeans = grpstats(x(:,2:end),x(:,1))

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by