Finding Mode and Median Without Mode and Median Function

6 visualizaciones (últimos 30 días)
Chloe Carter
Chloe Carter el 20 de Feb. de 2021
Comentada: Chloe Carter el 20 de Feb. de 2021
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.

Respuestas (1)

Steven Lord
Steven Lord el 20 de Feb. de 2021
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 comentario
Chloe Carter
Chloe Carter el 20 de Feb. de 2021
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

Iniciar sesión para comentar.

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by