# Replace elements of matrix when executing condition

**URL:** <https://discourse.julialang.org/t/replace-elements-of-matrix-when-executing-condition/96465>\
**Category:** General Usage\
**Created:** [March 22, 2023, 5:29pm UTC](https://discourse.julialang.org/t/replace-elements-of-matrix-when-executing-condition/96465 "2023-03-22T17:29:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey\_Novak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergey_novak/32/37716_2.png) [@Sergey\_Novak](https://discourse.julialang.org/u/Sergey_Novak)\
**Post date:** [March 22, 2023, 5:29pm UTC](https://discourse.julialang.org/t/replace-elements-of-matrix-when-executing-condition/96465/1 "2023-03-22T17:29:43Z")

</div>

Hello. I have next matrix:

```julia
200×200 Matrix{Float64}:
 -3.14652 -3.09094 -3.03716 -2.98602 … -0.311487 -0.311531
 -3.12573 -3.07036 -3.01627 -2.96592 -0.311478 -0.311522
 -3.10504 -3.05 -2.99531 -2.94675 -0.311469 -0.311513
 -3.08457 -3.0305 -2.97432 -2.92487 -0.31146 -0.311503
 -3.06458 -3.00903 -2.95338 -2.902 -0.311451 -0.311494
 -3.04586 -2.98748 -2.93264 -2.87993 … -0.311441 -0.311485
 -3.02346 -2.96667 -2.91254 -2.85823 -0.311432 -0.311476
 -3.00315 -2.94687 -2.89164 -2.83683 -0.311423 -0.311467
 -2.9838 -2.92585 -2.86976 -2.81585 -0.311414 -0.311458
 -2.96219 -2.90473 -2.84909 -2.79658 -0.311404 -0.311449
 -2.94434 -2.88677 -2.82908 -2.77362 … -0.311395 -0.311439
 -2.92147 -2.86342 -2.80701 -2.75228 -0.311386 -0.31143
 -2.90193 -2.84551 -2.78896 -2.73319 -0.311376 -0.311421
  ⋮ ⋱                
 -0.31226 -0.312244 -0.312227 -0.31221 -0.463892 -0.620582
 -0.312275 -0.312259 -0.312242 -0.312225 -0.381768 -0.540641
 -0.312289 -0.312273 -0.312257 -0.31224 … -0.300872 -0.45704
 -0.312303 -0.312287 -0.312271 -0.312255 -0.216553 -0.375224
 -0.312317 -0.312301 -0.312285 -0.31227 -0.135294 -0.291291
 -0.31233 -0.312315 -0.312299 -0.312284 -0.0488345 -0.208189
 -0.312343 -0.312328 -0.312313 -0.312298 -0.00152512 -0.123656
 -0.312356 -0.312342 -0.312327 -0.312311 … 0.000542308 -0.0400842
 -0.312369 -0.312355 -0.31234 -0.312325 -0.000553366 -0.00149448
 -0.312382 -0.312367 -0.312353 -0.312338 0.000419627 -0.000542405
 -0.312394 -0.31238 -0.312366 -0.312351 0.000920345 -0.0017566
 -0.312406 -0.312392 -0.312378 -0.312364 -0.00035279 0.000804297

```

I need to replace all elements of matrix wich less -0.1 on -0.8. How can i do it? I try methods which using for array and it doesn’t work.

---

<div class="post-metadata">

**Author:** ![dkzwart](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@dkzwart](https://discourse.julialang.org/u/dkzwart)\
**Post date:** [March 22, 2023, 6:18pm UTC](https://discourse.julialang.org/t/replace-elements-of-matrix-when-executing-condition/96465/2 "2023-03-22T18:18:49Z")

</div>

I’m not exactly sure what you are trying to do. Some math examples would be helpful.

Perhaps you mean something like:

```julia
a[-0.8 .< a .< -0.1] .= 0

```

---

<div class="post-metadata">

**Author:** ![Sergey\_Novak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergey_novak/32/37716_2.png) [@Sergey\_Novak](https://discourse.julialang.org/u/Sergey_Novak)\
**Post date:** [March 23, 2023, 6:21am UTC](https://discourse.julialang.org/t/replace-elements-of-matrix-when-executing-condition/96465/3 "2023-03-23T06:21:48Z")

</div>

Thank you!  
Yes, this is exactly what I need
