find the same values and average it out
1 view (last 30 days)
Show older comments
I have the following matrix A:
A =
66 2
66 3
66 4
67 6
67 3
68 5
69 6
69 3
what I would like to do is find the values that are the same in the first column and average the values in the second column and put it into a new matrix (B).
for example: I look for "66" and average the corresponding values in the second columns (i.e. 2,3,4) and the the mean is 3. So the first entry in matrix B will be:
B =
66 3
0 Comments
Answers (1)
Azzi Abdelmalek
on 19 Aug 2014
A =[ 66 2
66 3
66 4
67 6
67 3
68 5
69 6
69 3]
[ii,jj,kk]=unique(A(:,1))
out=[ii accumarray(kk,A(:,2),[],@mean)]
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!