Finding Mode and Median Without Mode and Median Function

How do I find the mode and medians of different columns without using the mode or median function (requested by assignment)? I have 22 rows and 29 columns I need to get modes for.

Answers (1)

If I gave you a list of numbers:
A = randi(10, 1, 7)
A = 1×7
10 8 3 3 6 4 6
How would you compute the mode and median of A with pencil and paper (or marker and whiteboard, or stick and sandbox, or $WRITING_UTENSIL and $SOMETHING_TO_WRITE_ON)? Once you have a process in mind, figure out how to implement that process using MATLAB code.
Or your textbook may have a suggestion for the right algorithm to use, in which case you will need to figure out how to implement that algorithm.
If after identifying the process / algorithm you have difficulty implementing it describe (in words) the process or algorithm, show us the code you've written to try to implement it, and describe in detail the difficulty you're experiencing.

1 Comment

I think I finally figured it out using these, but thank you!
%mode
for i=1:c;
A=Data(:,4:29);
u=unique(Data(:,4:29));
[n,b]=histc(A,u);
[n,is]=sort(n,'descend');
m=A(arrayfun(@(x) find(b==x,1,'first'),is));
[n,m]
end
%median
for i=1:c;
[Sort(:,4:29)]=sort(Data(:,4:29));
[Median(1,:)]=Sort(11,:);
[Median(2,:)]=Sort(12,:);
[Median(3,i)]=((Median(1,i)+Median(2,i))/2);
end

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

on 20 Feb 2021

Commented:

on 20 Feb 2021

Community Treasure Hunt

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

Start Hunting!