Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Replace negative values in matrix with zero

    Hi All,
    I have what I think is a very simple question. I would like to replace all the negative values of a matrix with zero. In Matlab this would be straightforward but I cannot figure out how to do it in Mata. Can anyone help?
    Thanks!

  • #2
    One way to do it

    Code:
    : y = (-2, -1 \ 1, 2)
    
    : (y :>= 0) :* y
           1   2
        +---------+
      1 |  0   0  |
      2 |  1   2  |
        +---------+

    Comment


    • #3
      Oh fantastic. I should have thought of this. Thanks Nick!

      Comment

      Working...
      X