How to compare all matrix cells to the median value?
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
sushma swaraj
le 6 Juil 2023
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!
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!