edit: final code for this case:
"What I am working with is a 842,382x3 matrix where the first column is a repetition of numbers 1-365 (year 1), 1-365 (year 2), counting up through the years every time 1-365 and then starting again. The columns 2 and 3 are holding data that is directly related to the day of the year.
I am looking to find a way to put the occurance of 1-365 the first time to be (1992) and then the second time it runs through 1-365 be (1993)."
data = my_matrix;
rows = size(my_matrix,1);
start_year = 1992;
start_month = 1;
start_day = 1;
idx = [find(diff(data(:,1))<0) ; rows];
y = repelem((1:length(idx))',diff([0;idx]));
tmp_check = [data(:,1) y]
t = datetime(start_year-1+y,start_month,start_day-1+data(:,1)');
m = month(t);
TT = array2timetable(data(:,2:3),'RowTimes',t);
G = groupsummary(TT,'Time','month','mean');
---------------------------------------------------------------------------------
What form does the time stamp data take? Is it in an 800,000 x 1 array? Are the values just the integers 1-365, or is there extra info?
Let's say each row is a different day, with no gaps. You'd use this:
rows = 8e5;
data = rand(rows,3);
start_year = 1970;
start_month = 1;
start_day = 1;
t = datetime(start_year,start_month,start_day-1+(1:rows));
TT = array2timetable(data,'RowTimes',t);
G = groupsummary(TT,'Time','month','mean');
G = groupsummary(TT,'Time','monthname','mean');
If parts of this aren't quite what you need, ask here and/or check the documentation for datetime (esp. if you have an array of date data), timetables, and groupsummary
Best Answer