How can I transform these data into seasonal data?

3 次查看(过去 30 天)
Hello everyone,
I should transform these data into seasonal data:
1) December-January; 2) From March to October; 3) November; 4)February.
Thank you!

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-8-12
编辑:Scott MacKenzie 2021-8-12
@Pul. Here's a solution that allows you to get summary statistics by season:
load('testdata.mat'); % loads giulia_TT timetable
% create logical vector for each season
s1Logical = month(giulia_TT.Time) == 12 | month(giulia_TT.Time) == 1; % Dec, Jan
s2Logical = month(giulia_TT.Time) >= 3 & month(giulia_TT.Time) <= 10; % Mar to Oct
s3Logical = month(giulia_TT.Time) == 11; % Nov.
s4Logical = month(giulia_TT.Time) == 2; % Feb.
sAll = s1Logical*1 + s2Logical*2 + s3Logical*3 + s4Logical*4;
% add column for season: 1, 2, 3, 4
giulia_TT.Season = sAll;
% convert to table and compute some group stats by season
T = timetable2table(giulia_TT);
data = T(:,{'Var5','Season'});
statarray = grpstats(data, 'Season', {'mean' 'std'})
% plot var5 vs season with +/-1 sd in error bars
x = statarray.Season;
yMean = statarray.mean_Var5;
ySTD = statarray.std_Var5;
b = bar(x, yMean, 'facecolor', [.8 .8 .9]);
set(gca, 'YLim', [0 120]);
title('Var5 by Season');
xlabel('Season');
ylabel('Mean');
% add error bars showing +/- 1 SD
hold on;
eb = errorbar(x, yMean, ySTD, ySTD);
eb.Color = [.5 .5 .9];
eb.LineStyle = 'none';
eb.LineWidth = 1.5;
% display values in bars
s = sprintf('%.2f,', statarray.mean_Var5);
s(end) = []; % remove trailing semi-colon
s = split(s, ',');
text(b.XEndPoints, b.YData * 0.4, s, 'b', 'fontsize', 12, 'horizontalalignment', 'center');
Stats table output:
Bar plot output:
  8 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by