Replace Values Larger than Threshold with New Value, But Keep Smaller Values

73 ビュー (過去 30 日間)
Hi all,
I have a 600 x 2 matrix, and I would like to check which values within the first column exceed a threshold. For example, I would like to replace all values that exceed 180 with that number minus 250 (e.g. 270 would be replaced with 20 because 270 - 250 equals 20). However, I would like to keep the values that are below 180 the same. In essence, I'm trying to keep the original order established by the original matrix, but I just need to replace those values greater than 180 with new values. Any hints? (This should be really easy, and I'm sure I'll find a solution eventually, but right now my stress isn't helping me see clearly.)
Thanks in advance!

採用された回答

the cyclist
the cyclist 2021 年 1 月 28 日
If A is your matrix, then
idx = A>180;
A(idx) = A(idx) - 250;
  1 件のコメント
Michelle De Luna
Michelle De Luna 2021 年 1 月 28 日
@the cyclist: Thank you for your help! I sincerely appreciate it. Have a great evening! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by