How to average the values in the third column with respect to some interval in first column??

Hi I have a problem in analyzing a matrix. Suppose i have m*3 matrix having values of latitude, longitudes and height, for example say (0.01,0.5,0.8,1.0,2.5,3.6,5.6,40.0,37.5.....n; 88.9,60.5, 60.6, 87.5, 85.3,99.9, 84.6, 89.5, 90.3, 60.5, 61.3 ....n; 455, 481, 452, 355,............n); the latitude and longitudes values are not ascending or descending, these are scattered values.. if i have to average the values in the third column i.e., height for some interval in the first column i.e., latitude 0-2, 2-4, 4-6.....38-40 (0:2:40) how can i do it sir? please help ...thanks again

 Accepted Answer

[~,idx] = histc(LatitudeValues, 0:2:40)
result = accumarray(idx, HeightValues, [], @mean)

4 Comments

by using [~,idx] = histc(LatitudeValues, 0:2:40), idx is containg some values like 15,15,15,15....8,8,8....i didnot get what does it exactly mean??? would you please explain sir??
idx is the number of the bin a specific value of LatitudeValues belongs to. With the help of the function accummarray, we can calculate the mean of all HeightValues that have the same value of idx, i.e., belong to the same bin.
Sir, the above code is for averaging the third column with respect to first column...if i have another columns say 3:125; How can I average all the columns with respect to first column similar to above example. I mean Height values have columns 3:125. Should I use the same code as above?
instead of averaging how can i count the number of height values appearing...should i do in the following way??
[~,idx] = histc(LatitudeValues, 0:2:40) result = accumarray(idx, HeightValues, [], @count)
but not getting the number of values...please help

Sign in to comment.

More Answers (0)

Asked:

on 7 Apr 2014

Commented:

on 17 Apr 2014

Community Treasure Hunt

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

Start Hunting!