Behzad - I don't really understand why in your code you have variables named table and then tbl. Perhaps both are the same variable and so there has been a typo in your code. I do recommend against using variable names that are identical to built-in MATLAB function (see table). If you want to loop over each set of 30 year data in your cell array then you could try something like load ExampleCell.mat;
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], ["Spring", "Summer", "Autumn", "Winter"]);
[group, mean_table] = findgroups(sampleTableData(:, 'seasons'));
mean_table.rrr24 = splitapply(@sum, sampleTableData.rrr24, group);
for k = 1:4
meanTableDataArray{j,k} = mean_table(k,:);
end
end
I haven't tested the above but I think that it will give you an idea of what you can do. Note how it is more similar to the first block of code that you posted, and that the only indexing we use (with j) is when we extract the jth table data.
Best Answer