# Calculate if statement based on date

12 views (last 30 days)
CMatlabWold on 28 May 2020
Commented: CMatlabWold on 31 May 2020
Hello,
I have a spreadsheet. In column A, are the dates. In column E, I have the precipitation values.
I need to sum certain precipitation values (of Column E) together per date, based on Latitude and Longitude, columns F and G respectively. Then, I need to designate either S1, S2, ...
For instance, I need to calculate the sum of precipitation values for S12 for each date. S12 is based on the following Latitude and Longitude values:
40.6323 -74.1923
40.5935 -74.1066
40.5804, 74.175
40.561, -74.1322
40.5478, -74.2005
40.5284, -74.1577
40.5153, -74.226
If any one could help me with this, I would greatly appreciate it.
I've attached a spreadsheet that covers about 20 days, since my file was too big (its 3,650 days).
Thanks,
Candace
darova on 28 May 2020
What is the criteria of group? I don't understand how to separate values

Star Strider on 28 May 2020
Try this:
TT1 = table2timetable(T1);
TTRP = retime(TT1(:,1:4), 'daily', 'sum');
TTRL = retime(TT1(:,5:6), 'daily', 'mean');
TTR = innerjoin(TTRP,TTRL)
producing:
TTR =
36×6 timetable
Date Precip (mm) PRECIP (in) Weights Final PRECIP Latitude Longitude
___________ ___________ ___________ _______ ____________ ________ _________
01-Jan-2010 846.6 33.331 55.27 23.292 40.671 -73.985
02-Jan-2010 184.5 7.2638 55.27 3.9852 40.671 -73.985
03-Jan-2010 65.8 2.5906 55.27 1.471 40.671 -73.985
04-Jan-2010 8.2 0.32283 55.27 0.23122 40.671 -73.985
05-Jan-2010 0 0 55.27 0 40.671 -73.985
06-Jan-2010 0 0 55.27 0 40.671 -73.985
07-Jan-2010 0 0 55.27 0 40.671 -73.985
08-Jan-2010 59.1 2.3268 55.27 1.6153 40.671 -73.985
... CONTINUED ...
.
CMatlabWold on 31 May 2020
Hi, thanks for the code.
But, what I am trying to do is add the final precip amounts based on latitude and longitude coordinates.
For instance, in the case of S12, which is comprised of these coordinates:
Latitude Longitude
40.6323 -74.1923
40.5935 -74.1066
40.5804, 74.175
40.561, -74.1322
40.5478, -74.2005
40.5284, -74.1577
40.5153, -74.226
The corresponding Final Precip amounts for January 1, 2010 are listed in column E (If I filter the spreadsheet tab, I get these values on column E:
E F G
0.0580 40.6323 -74.1923
0.0743 40.5935 -74.1066
0.0881 40.5804, 74.175
0.0660 40.561, -74.1322
0.0579 40.5478, -74.2005
0.103 40.5284, -74.1577
0.0269 40.5153, -74.226
And, I just want to have Matlab sum these amounts per day.
For, instance, the sum for January 1, 2010 is 0.4742 inches

### Community Treasure Hunt

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

Start Hunting!

Translated by