- 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 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!