フィルターのクリア

How to compare all matrix cells to the median value?

2 ビュー (過去 30 日間)
Ziad Osman
Ziad Osman 2023 年 6 月 29 日
回答済み: sushma swaraj 2023 年 7 月 6 日
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

採用された回答

Shantanu Dixit
Shantanu Dixit 2023 年 6 月 29 日
編集済み: Shantanu Dixit 2023 年 7 月 1 日
Hi Ziad,
  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:
  1. median - MATLAB - Mathworks
  2. Find Array elements that meet a particular condition - MATLAB - Mathworks

その他の回答 (1 件)

sushma swaraj
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!

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by