Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

4 次查看(过去 30 天)
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.

回答(1 个)

the cyclist
the cyclist 2016-2-9
编辑:the cyclist 2016-2-9
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!

Translated by