Hey all, I have a 1×3 cell with three 360×3 table. Each table has a column date with 30 years of the monthly data (30×12 = 360).
So I used this code below:
%get first array of the cell
table = CELL{1};table.month = month(tbl.dates);table.seasons = floor(tbl.month ./ 3);table.seasons(tbl.seasons == 4) = 0;table.seasons = categorical(tbl.seasons, [0 1 2 3], ["Spring", "Summmer", "Autumn", "Winter"]); [group, mean_table] = findgroups(table(:, 'seasons'));mean_table.rrr24 = splitapply(@sum, table.rrr24, group);
This code above calculates seasonal data just for the first array of the cell:
meanTbl = 4×2 table season rrr24 ______ ______ Spr 14.038 Sum 35.004 Aut 10.949 Win 16.958
Now I want to apply the above-mentioned code to all arrays of cell; then save the result in another cell (3 x 4, Three years and four seasons).
Here is my try I want to ask you if you please correct me:
for i = 1:numel(CELL) table.month(i) = month(table(i).dates); table(i).seasons = floor(table(i).month ./3); table(i).seasons(table(i).seasons ==4) = 0; table(i).seasons = categorical(table(i).seasons, [0 1 2 3], ["Spring", "Summer", "Autumn", "Winter"]); [group, mean_table(i)] = findgroups(table(i)(:, 'seasons')); mean_table(i).rrr24 = splitapply(@sum, table(i).rrr24, group); for j = 1:3 newCELL{j,i} = mean_table(i); %newCELL is 3 x 4 cell array
endend
Thank you so much.
Best Answer