Sum Like Kind (not cumsum)

Suppose I have two vectors (A and B). Vector A contains year,month,day in serial format. Vector B contains _cumulative precipitation data (0, 0.01, 0.02, 0.03, NaN, 0.04, NaN, NaN, NaN, 0.05). Each event (bucket tip) is equal to 0.01 in. Note, NaN values are associated with no data measurements (i.e., no rainfall) and the rainfall data is cumulative. I've compiled this data in a matrix.
I'd like to determine the daily total precipitation amount. So I'd like to sum the precipitation values associated with a unique serial date (year, date, month) over the data range. I don't want to sum the whole column, I only want to sum all precipitation values associated with a unique serial date.
Any ideas?

Answers (1)

I don't know what the format is for your serial data so I'll just give an example where I add values of y when x is within a region. I hope this is what you look for.
x = [1 2 3 4 5 6]
y = [0.01 0.02 NaN 0.04 0.05 0.06]
x_nonan = x(~isnan(y))
y_nonan = y(~isnan(y))
sumval = sum(y((1<x)&(5<=x)))

This question is closed.

Asked:

on 1 Feb 2012

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!