Borrar filtros
Borrar filtros

How can I find the median of each row in a matrix?

1 visualización (últimos 30 días)
Whale Chicken
Whale Chicken el 3 de Mayo de 2021
Comentada: Image Analyst el 5 de Mayo de 2021
I have a matrix 150x4, how can I create a function to get the median values of all the rows? Without using matlabs existing functions
Final result should be 150 medians

Respuestas (1)

Doddy Kastanya
Doddy Kastanya el 5 de Mayo de 2021
Try this (assuming that your matrix is called A):
for i=1:150
x=sort(A(i,:));
median_value(i)=0.5*(x(2)+x(3));
end
You will get a vector of median_value at the end with 150 entries.
  1 comentario
Image Analyst
Image Analyst el 5 de Mayo de 2021
sort() is an existing MATLAB built-in function that Whale says is not allowed. You'd need to write your own sort routine from low level commands. See Wikipedia for the algorithm.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by