How can I work out the median of frequency tables?
5 views (last 30 days)
Show older comments
Matthew Quigley
on 17 Mar 2018
Commented: Star Strider
on 17 Mar 2018
I currently have vector A that contains an ordered range of values, and vector B that contains the corresponding frequencies of these values.
What would I need to do in order to discover the median of the values in vector A, based on the frequencies in vector B?
0 Comments
Accepted Answer
Star Strider
on 17 Mar 2018
I would use the frequency vector ‘B’, since it has the information you need.
Try this:
A = sort(rand(1, 35)); % Create ‘A’
B = randi(99, size(A)); % Create ‘B’
Bcsn = cumsum(B)/sum(B); % Normalised Frequency Vector
median_idx = find(Bcsn <= 0.5, 1, 'last'); % Index Of Normalised Frequencies <= 0.5
A_median = A(median_idx); % Corresponding Element Of ‘A’
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!