Info

This question is closed. Reopen it to edit or answer.

How do i change values in an array of numbers based on their current value?

1 view (last 30 days)
Lets assume we have an array and some variables.
I=[32 12; 44 9]
T=30
I_T= I >30
We need to change the values of the elements of the array accordingly to T. For example, the first value is 32 which exceeds T. The value should be changed to 255. The second value is 12 which does not exceed T. Its value should be changed to 0. We need a function that does that for any given array length in the command window. Thanks in advance.

Answers (1)

the cyclist
the cyclist on 9 Feb 2016
Edited: the cyclist on 9 Feb 2016
loIdx = (I <= T);
hiIdx = (I > T);
I(loIdx) = 0;
I(hiIdx) = 255;

Community Treasure Hunt

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

Start Hunting!