How to replace elements in part of a matrix that meet a certain criteria?
Show older comments
I want to replace elements in certain rows and columns with 0, if they are greater or less than 0. As I am using a sparse matrix (that's 10 000 x 10 000) I don't think I can just set those rows equal to zero, so I am specifically looking for all nonzero elements and replacing them. I can do this row by row in a for loop over i: A( rows(i) , abs(A(rows(i),:))>0 )=0, if rows is a 1D array with row indices. I was wondering if there is a way to do this for the whole matrix without looping? I tried A( rows , abs(A(rows,:))>0 )=0, but that doesn't work as my logical array is 2D.
Accepted Answer
More Answers (0)
Categories
Find more on Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!