# MATLAB: How to create a matrix using conditional statements in a loop based in another matrix

for loop matrixmatrix manipulation

Hello,
I have a matrix and I want to generate another matrix according to their elements using a loop.
If one ore more elements of a row is ==0 the correspondent row in the new matrix need to be 0.
If not, it needs to be the sum of the elements in the row.
Comb =                                        % The initial matrix             0            0        4.303            0         2.68            0            0        1.705        4.303        1.705         2.68        1.705                             % I need this output:   H = [0       0       0       0       6.008       4.385]              
I started with this loop:
       for i = 1:size(Comb, 1)        for j = 1:size(Comb, 2)                          x = (sum(Comb'))'                         if abs(Comb(i,j)) == 0                                       end        end      end
But it gives that:
x =
0
4.303
2.68
1.705
6.008
4.385
I do not know what insert on the if to display zeros when one element of the row is equal to zero.
Could you help me ?
• H = all(Comb,2).*sum(Comb,2);