Finding Unique values of a variable

1 回表示 (過去 30 日間)
Mohana
Mohana 2015 年 4 月 6 日
コメント済み: Image Analyst 2015 年 4 月 8 日
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 日
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 月 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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by