Computing the median of a group except one member
Show older comments
I have a dataset of a variable x for S seasons of the same J firms (not ordered). I'd like to compute for each firm in each season, the median of all other firms in that season. e.g. S=2, J=6, my dataset is
M=[1 2 3 6 5 4 2 3 4 1 5 6; 1 1 1 1 1 1 2 2 2 2 2 2; 2 4 6 5 7 8 3 7 5 7 5 3]'
First column is the firm index, second column the season, third column the x values for each firm in each season.
I am thinking something like
for i=1:size(M,1)/6
for j=6*i-5:6*i
M(j,4)=median(M(6*i-5:6*i,3));
end
end
but with the index of M(:,3) inside median() somehow telling MATLAB to exclude the jth entry of M(:,3)?
Thank you!
8 Comments
madhan ravi
on 14 Feb 2019
Edited: madhan ravi
on 14 Feb 2019
Could you give a short example of your desired output?
wy6622
on 14 Feb 2019
madhan ravi
on 14 Feb 2019
You didn’t write your desired output yet?
wy6622
on 14 Feb 2019
Stephen23
on 14 Feb 2019
@weicheny: please show us the expected output, e.g.
3
or
[19,4,17.6]
or whatever you expect to get. It is much easier to test code when you provide an expected output we can check the code's output against.
wy6622
on 14 Feb 2019
madhan ravi
on 14 Feb 2019
ok did you get the answer to your question since you accepted the answer ?
wy6622
on 14 Feb 2019
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings 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!