- You can use "median()" function in MATLAB to compute the median of the matrix.
- Further you can create a logical matrix (same size as original matrix), fill in the values using logical operation comparing with the median value. (refer to 2nd documentation attached)
How to compare all matrix cells to the median value?
조회 수: 3 (최근 30일)
이전 댓글 표시
If the number in the cell is higher than the median of all the numbers in the matrix then the number in the cell wil be replaced by a 1 else by a 0
댓글 수: 0
채택된 답변
Shantanu Dixit
2023년 6월 29일
편집: Shantanu Dixit
2023년 7월 1일
Hi Ziad,
Refer to the documentation:
댓글 수: 0
추가 답변 (1개)
sushma swaraj
2023년 7월 6일
Hi Ziad,
Assuming you have a matrix named 'matrix' :
% Calculate the median of all the numbers in the matrix
medianValue = median(matrix(:));
% Create a new matrix where numbers greater than the median are replaced by 1, and others by 0
resultMatrix = zeros(size(matrix)); % Initialize with zeros
resultMatrix(matrix > medianValue) = 1; % Set values greater than median to 1
Hope it works!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!