Hi,
the following code reshapes your table the way you want it:
load('monthlymeans_ObsData.mat')
monthlymeans_ObsData.Properties.RowTimes.Format = 'MMM';
waterlevel = nan(564,1);
waterlevel(1:557) = monthlymeans_ObsData.timmendorf_waterlevel;
waterlevel = reshape(waterlevel,12,47);
T = splitvars(table(waterlevel));
years = cell(1,47);
for y = 1:47
years{y} = sprintf('Year_%d',1970+y);
end
T.Properties.VariableNames = years;
months = cell(1,12);
month_names = string(monthlymeans_ObsData.Properties.RowTimes(1:12));
for m = 1:12
months{m} = sprintf('%s',month_names(m));
end
T.Properties.RowNames = months;
clear waterlevel y years months month_names m ans
With this result you can access all data for the months May and June over all years that way:
T_may_june = T({'May', 'Jun'},:);
which results in a new table. Calculate mean and standard deviation for all years for may and june and append those values as columns:
T_may_june.mean = mean(T_may_june{:,:},2,'omitnan');
T_may_june.std = std(T_may_june{:,:},1,2,'omitnan');
If you like an array more you can use:
may_june = T_may_june{:,:};
Best regards
Stephan
Best Answer