For loop mean values into matrix

3 vues (au cours des 30 derniers jours)
Dario
Dario le 12 Mar 2018
I attach my matrix that is called diff_matr.
This matrix has 2 columns. In the first one there are values (ordered by ascending) of distances which go from 80 m. to 3600 m., in the second one there are values of power. I want a mean value of the power every 100 meters. All these values should be placed in a new matrix.
How can I do this? Thank you!
  1 commentaire
Rik
Rik le 12 Mar 2018
What have you tried yourself?

Connectez-vous pour commenter.

Réponse acceptée

Razvan Carbunescu
Razvan Carbunescu le 16 Mar 2018
You can use a groupsummary command in R2018a but have to convert it into table
>> T = array2table(diff_matr);
>> head(T)
ans =
8×2 table
diff_matr1 diff_matr2
__________ __________
88.824 0.97733
89.399 0.84026
89.708 0.78373
90.467 0.67573
90.859 2.4212
91.796 0.98031
92.268 1.2223
92.783 0.20184
>> GT = groupsummary(T,'diff_matr1',[0:100:3600],'mean')
GT =
37×3 table
disc_diff_matr1 GroupCount mean_diff_matr2
_______________ __________ _______________
[0, 100) 20 0.90776
[100, 200) 711 4.8311
[200, 300) 3692 5.6248
[300, 400) 5149 6.053
[400, 500) 3565 8.1586
[500, 600) 3767 13.229
[600, 700) 4751 15.098
[700, 800) 4376 18.386
[800, 900) 4877 23.764
[900, 1000) 5216 28.907
[1000, 1100) 5115 32.807
[1100, 1200) 6204 35.417
[1200, 1300) 6495 44.635
[1300, 1400) 7056 43.697
[1400, 1500) 7230 46.704
[1500, 1600) 8321 47.722
[1600, 1700) 8544 49.278
[1700, 1800) 8306 54.15
[1800, 1900) 8474 58.651
[1900, 2000) 9271 58.771
[2000, 2100) 10087 64.494
[2100, 2200) 10451 64.234
[2200, 2300) 10468 70.598
[2300, 2400) 9985 74.469
[2400, 2500) 10824 85.012
[2500, 2600) 10766 105.17
[2600, 2700) 11285 106.94
[2700, 2800) 11615 101
[2800, 2900) 12048 108.69
[2900, 3000) 11437 108.45
[3000, 3100) 11931 115.3
[3100, 3200) 10166 120.96
[3200, 3300) 9837 139.41
[3300, 3400) 8824 153.86
[3400, 3500) 8316 159.2
[3500, 3600] 8696 162.41
<undefined> 23032 171.14
There still seem to be 23000 rows outside those ranges you mentioned so maybe the height goes a bit higher or lower also.

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types 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