I have a 1×3 cell contains three 360×3 tables. For every table, I want to calculate the average of rrr24 for each season and write them on the 5th column. For example:
I have a code as you can see below, but it calculates the average of each season for all 30 years (not yearly), and didn't write averages on the 5th column too.
I would like just a new 1×3 cell with tables that have the 5th column as I described above.
meanTableDataArray = cell(length(CELL),4);for j = 1:length(CELL) sampleTableData = CELL{j}; sampleTableData.month = month(sampleTableData.dates); sampleTableData.seasons = floor(sampleTableData.month ./3); sampleTableData.seasons(sampleTableData.seasons ==4 ) = 0; sampleTableData.seasons = categorical(sampleTableData.seasons, [0 1 2 3], ["Spr", "Sum", "Aut", "Win"]); [group, mean_table] = findgroups(sampleTableData(:, 'seasons')); mean_table.rrr24 = splitapply(@mean, sampleTableData.rrr24, group); for k = 1:4 meanTableDataArray{j,k} = mean_table(k,:); % extracts as a table
endend
Thank you.
Best Answer