How to extract only postive values from a n x n matrix

5 views (last 30 days)
I have a 100X100 matrix with negative and positive values, and i need to find the sum of each row for values that are greater than zero.

Accepted Answer

Guillaume
Guillaume on 24 May 2015
m = randi([-20 20], 100); %demo data
sum(m .* (m>0), 2)
would work. Basically, replace negative numbers by 0 and take the sum.

More Answers (0)

Categories

Find more on Characters and Strings 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!