Extract values from a cell based on dates

2 visualizzazioni (ultimi 30 giorni)
Hi all,
I have data in 6 separate cells (A, B, C, D, E, F), all which are 365x1. One of these cells (A) contains dates as 'datenum' for a whole 12 months. My question is how can I call/pull/extract data from these cells based on date requirements and get an average. i.e. all of the values on the 10th for each month.
Would it be best to use stack and place them all as a table? I don't have any code for this yet as I don't know where to begin.
  7 Commenti
jonas
jonas il 8 Ott 2018
As was suggested several times already, what you want is a timetable and retime. If you want to calculate some statistics based on the "day of month", then I would suggest using the day of month as a grouping variable. This is easy if you first convert your data to datetime format, which you should do anyway.
Manuel Flores
Manuel Flores il 8 Ott 2018
Thanks everyone I'm taking the suggestions mentioned and importing it as a table.

Accedi per commentare.

Risposta accettata

jonas
jonas il 8 Ott 2018
Modificato: jonas il 8 Ott 2018
Here's another approach
%%Dummy dataset
Date = datetime('2000-01-01')+days(0:364);
Date.Format = 'dd/MMM/yyyy';
Data = rand(numel(Date),5);
%%Data to timetable
TT = timetable(Date',day(Date)',Data)
TT = splitvars(TT)
TT.Properties.VariableNames = {'DayOfMonth','C1','C2','C3','C4','C5'}
TT =
366×6 timetable
Time DayOfMonth C1 C2 C3 C4 C5
___________ __________ _________ __________ __________ _________ _________
01/Jan/2000 1 0.83516 0.64556 0.79434 0.73071 0.068773
02/Jan/2000 2 0.11948 0.47084 0.92745 0.75217 0.19456
03/Jan/2000 3 0.76848 0.28703 0.54273 0.59603 0.94978
...
Continuing...
%%Mean, std and max with DayOfMonth as grouping variable
[s1,s2,s3] = grpstats(TT.Variables,TT.DayOfMonth,{'mean','std','max'})
%%Monthly average using retime
TT2 = retime(TT,'monthly','mean')
s1, s2 and s3 are matrices with 31 rows representing the selected statistics for each day of the month.
  7 Commenti
Manuel Flores
Manuel Flores il 9 Ott 2018
Hey gents I have another question.
I have a code like this where I pull the data based on those 4 dates. That works, so no problem there.
% Pull the Temperature from the design dates.
Tr = {'2017-07-01','2017-07-02','2017-08-01','2017-08-02'};
Tj = TT_all(Tr,2);
Now I'm wondering how to do the same for 28 day for every month over 12 months. Obviously it's not like this.
Tr_all = {'2017-07-01:2017-07-28','2017-08-02:2017-08-28','2017-09-01:2017-09-28'}...
{'2017-10-01:2017-10-28','2017-11-01:2017-11-28','2017-12-01:2017-12-28'}...
{'2018-01-01:2011-01-28','2018-02-01:2011-02-28','2018-03-01:2011-03-28'}...
{'2018-04-01:2011-04-28','2018-05-01:2011-05-28','2018-06-01:2011-06-28'};
can you point me in the right direction please. Thanks
jonas
jonas il 9 Ott 2018
Modificato: jonas il 9 Ott 2018
Easier would be
TT(day(TT.Time)==28,:)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by