Before the loop,
J = 0;
First statement inside the loop:
J = J + 1;
Then in the if/else portion, instead of assigning to pH, assign to pH(J)
Note: your code would be much more efficient if vectorized.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!