MATLAB: How to decrease index of an vector on every time step

cumsumdecreaserainfallvector

This seems like a fairly straight forward thing to do, however it has been giving me all sorts of trouble.
I am working on a geophysical model, and part of that involves a rainfall rate, and once surface temperatures gets to 100C, subsequent rainfall will accumulate as a reservoir. However, a fraction of this will still evaporate each timestep.
So as you can see below, during times of rainfall, the surface can reach 100C. I to plot another variable however, to show the water that has accumulated in on the surface.
The maths is a little more complex, but lets say 1% is evaporated each timestep, I simply want the reservoir to decrease by 1% each step.
I think the main issue I am having is that the water can only begin to accumulate on the surface when it has reached 100C, continues to accumulate until the rain stops and as soon as the rain stops the accummulated water value will begin to decrease. But the way I have it coded, as soon as the rain stops, the temperature increases and the water in the reservoir isn't considered.
What I am looking for, would be a plot similar in shape to the 'Total Rain' plot, but that begins to decrease once T rises, not remains constant until it rains again.
Here is the code I have:
for n = timesteps
if T(n,1)>373
T(n+1,1) = equation1; % surface temp
else
T(n+1,1) = equation2; % surface temp = 373K
rainTotalAccum = cumsum(rain);
if rainTotalAccum(n)>0
T(n+1,1) = equation2; % To try and stop T increasing once rain stops if there is surface water present
rTotalAccum(n) = rTotalAccum(n) - rTotalAccum(n)*0.01; % 1% of rain evaporated each timestep
end
end
end
What I need is a way to decrease the value of rainTotalAccum each timestep, keeping the temperature at 373K, but everything I have tried so far has failed. I'd really appreciate any advice on this.

Best Answer

I don't have all your code so I can't be sure this is the problem but:
rTotalAccum(n) = rTotalAccum(n) - rTotalAccum(n)*0.01;
Shouldn't this be
rTotalAccum(n+1) = rTotalAccum(n) - rTotalAccum(n)*0.01;
Also you are running
T(n+1,1) = equation2;
twice and I don't think that is intentional.
Related Question