How can I transform these data into seasonal data?

4 ビュー (過去 30 日間)
Pul
Pul 2021 年 8 月 12 日
コメント済み: Scott MacKenzie 2021 年 8 月 12 日
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 件のコメント
Pul
Pul 2021 年 8 月 12 日
Thanks for you help.
Scott MacKenzie
Scott MacKenzie 2021 年 8 月 12 日
You're welcome. Glad to help. Good luck.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by