Replace elements of matrix when executing condition

Hello. I have next matrix:

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.

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

Perhaps you mean something like:

a[-0.8 .< a .< -0.1] .= 0
4 Likes

Thank you!
Yes, this is exactly what I need

1 Like