How to compare all matrix cells to the median value?

4 visualizzazioni (ultimi 30 giorni)
Ziad Osman il 29 Giu 2023
Risposto: sushma swaraj il 6 Lug 2023
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Shantanu Dixit il 29 Giu 2023
Modificato: Shantanu Dixit il 1 Lug 2023
1. You can use "median()" function in MATLAB to compute the median of the matrix.
2. 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)
Refer to the documentation:
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Più risposte (1)

sushma swaraj il 6 Lug 2023
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by