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

조회 수: 4 (최근 30일)
Whale Chicken
Whale Chicken 2021년 5월 3일
댓글: Image Analyst 2021년 5월 5일
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

답변 (1개)

Doddy Kastanya
Doddy Kastanya 2021년 5월 5일
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
Image Analyst
Image Analyst 2021년 5월 5일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by