x=length(y) is a scalar value, just the length. You then pass that one length as the X coordinates and pass all of y as the Y coordinates. When you pass a scalar as the X coordinates then trapz treats it as the difference between successive X values. It seems unlikely that the difference between X values just happens to be the same as the number of Y values.
Your for loop is processing only that one calculation because the =length(y) part is a scalar.
If you were to change that to be a range like 1:length(y) then you would be overwriting the int variable each iteration.
Your y is a vector. When you test a vector in an if statement the test is true only if all of vector values are nonzero simultaneously. Your body of the if will not fire once for each y that is greater than 0: it will fire once total if ALL of the y are greater than 0 and not at all if even one y is not positive.
Suppose your y is 1 2 3 -1 5 6 then how do you want to process only the positive values? Do you want to trapz 1 2 3 and add trapz 5 6 (each block of positive values independently) or do you want to process 1 2 3 5 6 as if the 5 were immediately beside the 3, or do you want to process like 1 2 3 0 5 6 (negative values become 0) or do you want to "hold" the last positive value through the gap, like 1 2 3 3 5 6?