0
$\begingroup$

For an array TestA={15,12,5,8,6}, I want to change the value of number greater than 10 into 0, as TestB={0,0,5,8,6}. When using "Select" command, I will lose some numbers. Thanks.

$\endgroup$
  • $\begingroup$ Have you seen /; (Condition) in the documentation with respect to replacement (/.)? $\endgroup$ – eyorble Aug 1 '19 at 15:33
  • $\begingroup$ Oh, thank you, it's very useful. $\endgroup$ – Wang Shen Aug 1 '19 at 15:40
0
$\begingroup$

This should do:

TestA = {15, 12, 5, 8, 6} /. x_ /; x > 10 -> 0
$\endgroup$
1
$\begingroup$

You can also use Clip:

Clip[{15, 12, 5, 8, 6}, {0, 10}, {0, 0}]

{0, 0, 5, 8, 6}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.