Finding Unique values of a variable
Afficher commentaires plus anciens
I have dataset as shown below
41481 1 28.08 28.2 28.08 68.09
41481 16 28.06 28.15 28.04 68.08
41481 31 28.08 28.13 28.02 68.17
41482 1 28.3 28.63 28.28 67.86
41482 16 27.48 28.32 27.47 67.72
41482 31 26.8 27.5 26.8 67.57
41482 46 26.65 26.83 26.61 66.37
41482 101 26.49 26.67 26.49 64.75
41482 116 26.49 26.58 26.48 63.77
41483 1 28.36 28.47 28.34 65.99
41483 16 28.33 28.41 28.32 65.86
41483 31 28.34 28.38 28.29 65.81
41483 46 28.29 28.36 28.25 65.74
41483 101 28.2 28.31 28.18 65.66
41483 116 28.12 28.21 28.06 65.59
41483 131 27.95 28.12 27.94 65.56
41483 146 27.91 27.99 27.91 65.5
: : and so on
I need to find the average values of 41482, 41482, 41483 etc. I have written the following code
load input.txt
d=input(:,1);
Tm=input(:,2);
Atmp=input(:,3);
Mxtmp=input(:,4);
Mntmp=input(:,5);
[u i j] = unique(d);
for i=1:length(u)
a(i,j)= mean(input(u(i),3:5))
end
i am not not getting proper results. What is the problem with the code, can any one help Thanks in advance. Regards.
Réponses (1)
Image Analyst
le 6 Avr 2015
Don't use input as the name of a variable since it's already the name of a built-in function. Use theInputArray or something similar.
To calculate column means, just do this
columnMeans = mean(theInputArray);
It's not clear when you say "I need to find the average values of 41482, 41482, 41483 etc." if you meant to take the mean of all the values, or of just the unique values.
4 commentaires
Mohana
le 6 Avr 2015
Image Analyst
le 6 Avr 2015
column1 = theInputArray(:,1);
column1Mean = mean(unique(column1));
Mohana
le 8 Avr 2015
Image Analyst
le 8 Avr 2015
And why do you think mean() does not take the average? It will take the average of any numbers, regardless of what they represent.
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!