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

69 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

the cyclist
the cyclist am 28 Jan. 2021
If A is your matrix, then
idx = A>180;
A(idx) = A(idx) - 250;

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by