Here's an approach to accomplish this task:
main.m256 chars11 lines
Explanation:
data
is a sample data matrix with 10 rows and 5 columns, but you can replace it with your own data.for
loop iterates over the columns of the data
matrix.data(:, col) < 0
expression creates a logical index of all the rows in the column col
that have negative values.data(data(:, col) < 0, col) = 0
assigns the value of 0 to all the cells in the col
column of data
matrix that have negative values, using logical indexing.After running this code, the matrix data
will have all its negative values replaced with 0.
gistlibby LogSnag