How can I transform these data into seasonal data?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pul
le 12 Août 2021
Commenté : Scott MacKenzie
le 12 Août 2021
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 commentaires
Réponse acceptée
Scott MacKenzie
le 12 Août 2021
Modifié(e) : Scott MacKenzie
le 12 Août 2021
@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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!