Rainfall Accumulation Event Based

2 vues (au cours des 30 derniers jours)
Alexander Osborne
Alexander Osborne le 24 Avr 2023
Hello,
I am trying to caluculate the rainfall accumulation for during 'events'. Here is an example of what the rainfall data looks like and what I would like it to output. I have tried methods that use accumarray and cumsum but they tend to only give a total per event, and not it counting up each time.
Any help would be greatly appreciated. Thanks.
Rainfall= [0 1 1 2 0 0 0 0 2 4 5 2 0 0]
Output= [0 1 2 4 0 0 0 0 2 6 11 13 0 0]

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 24 Avr 2023
%Added values at end points
y = [-6 -8 -10 0 1 1 2 0 0 0 0 2 4 5 2 0 0 3 5 7];
for k=2:numel(y)
if y(k-1) && y(k)
y(k)=y(k)+y(k-1);
end
end
disp(y)
-6 -14 -24 0 1 2 4 0 0 0 0 2 6 11 13 0 0 3 8 15
  1 commentaire
Alexander Osborne
Alexander Osborne le 24 Avr 2023
Perfect, thank you very much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by