How can I transform these data into seasonal data?
4 ビュー (過去 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!
0 件のコメント
採用された回答
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 Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!