Find the median of sequential duplicate entries
Show older comments
Hi! So I have a matrix
num =
1 4
2 4
3 4
4 4
5 5
6 6
7 6
8 6
9 6
10 6
11 7
....
31 14
32 14
33 13
34 12
35 12
36 12
37 12
38 12
39 9
40 9
41 9
42 9
43 8
44 8
45 8
46 8
47 5
48 5
49 4
50 3
And I want to take the median of the x entries with sequential y entries that are duplicate such that
inum =
2.5 4
5 5
8 6
11 7
....
31.5 14
33 13
36 12
40.5 9
44.5 8
47.5 5
49 4
50 3
I am using unique such that
[C,ia,ic] = unique(num(:,2),'stable')
OutMatrix = [accumarray(ic, num(:,1), [], @median ) ,C];
However, my outmatrix is showing the median of all the x entries that have y values that are the same i.e It took the median of 1,2,3,4,49 and not the median on 1,2,3,4 and 49 How do I do this? Thanks
Accepted Answer
More Answers (1)
Image Analyst
on 24 May 2014
1 vote
Do you have the Image Processing Toolbox? It's not too hard if you do - just use regionprops(). Let me know if you want to use that approach.
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!