Hello I have a data array (mat) with the following dimensions: 149016x93 The columns are year | month | day | hour | data 1 | data 2 | data 3 | and so on until data 89 2001 | 1 | 1 | 0 | random numbers ... ... | ... | ... | ... | random numbers ... 2017 | 12 | 31 | 23 | random numbers ... The data is random and it is what I want to average. I found this example (MathWorks example) and it is fine, however I've been strugling in how to run it over column 5 to 93... [ah,~,ch] = unique(mat(:,2:4),'rows'); hraverage = [ah,accumarray(ch,mat(:,5),[],@nanmean)]; y problem is that I'm not being able to have as an output the 8784x93 array, only an 8784* x 4, I've tried loops but i'm missing something that I am not aware of... *The dataset has several years of data. I want the hour average for each each day of the year. So it's 366 days * 24hours = 8784 for the sake of example, please feel free to consider a smaller array. thank you for the attention! will keep digging on this... sample data in attachment. randomly generated: 4 first collumns are: year, month, day, hour, and columns 5 to 7 are data columns. the final result should be a 8784x7 file.
Kshitij Singh answered .
2025-11-20
sampledata.Time = datetime(sampledata.Year,sampledata.Month,sampledata.Day)
result = groupsummary(sampledata,{'Time','Hour'},{'dayofyear','none'},'mean',{'VarName5','VarName6','VarName7'},'IncludeEmptyGroups',1)