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?

답변 (1개)

Honglei Chen
Honglei Chen 2012년 2월 1일

0 개 추천

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)))

이 질문은 마감되었습니다.

질문:

2012년 2월 1일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by