Finding Unique values of a variable

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.

답변 (1개)

Image Analyst
Image Analyst 2015년 4월 6일

0 개 추천

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

Mohana
Mohana 2015년 4월 6일
I need mean of unique values.
column1 = theInputArray(:,1);
column1Mean = mean(unique(column1));
Mohana
Mohana 2015년 4월 8일
Hi, This gives the average value of the first column, but i need the average values of data of 41481, 41482 which are dates.
Image Analyst
Image Analyst 2015년 4월 8일
And why do you think mean() does not take the average? It will take the average of any numbers, regardless of what they represent.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

태그

질문:

2015년 4월 6일

댓글:

2015년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by