Plotting of yearly data.

7 vues (au cours des 30 derniers jours)
Zunaira Akmal
Zunaira Akmal le 10 Déc 2019
Modifié(e) : per isakson le 13 Déc 2019
i have dataset of 15 years temperature dataset in a text file, i want to plot it years wise as plot of first year data to be on above the second year and so on, remeber data is not equally divided which means year 1 may have data of 6 months, year 2 have 12 months and so on. Data format is 09/02/2005 54.6 43.6 . . . . 11/11/2019 65.9 56.6 it is stored in a text file, i want to plot data of second column w. r. t years. here is the dataset.
i will be really obliged if anyone will help me in this.
  4 commentaires
dpb
dpb le 10 Déc 2019
Attach a .mat or .txt file here...we don't go to external sites.
Zunaira Akmal
Zunaira Akmal le 11 Déc 2019

Connectez-vous pour commenter.

Réponses (1)

Eric Sofen
Eric Sofen le 13 Déc 2019
Modifié(e) : per isakson le 13 Déc 2019
There are a few ways to tackle this problem. Here's one approach:
fi = '~/Downloads/Mod21_All_Inclusive_Data_Nov2019.txt';
opts = detectImportOptions(fi,"ConsecutiveDelimitersRule","join","Delimiter",{' ', '\t'});
t = readtable(fi,opts);
t(:,5:9) = [];
t.Time = t.Var1+duration(t.Var2,'InputFormat','hh:mm');
% Year comes in as 0007, not 2007
t.Time = t.Time + calyears(2000);
t(:,1:2) = [];
t.Time.Format = 'default';
head(t)
ans =
8×3 table
Var3 Var4 Time
_____ ______ ____________________
65.11 13.666 02-Sep-2005 08:33:00
65.27 13.668 02-Sep-2005 08:48:00
65.6 13.669 02-Sep-2005 09:03:00
66.1 13.669 02-Sep-2005 09:18:00
66.93 13.667 02-Sep-2005 09:33:00
67.43 13.669 02-Sep-2005 09:48:00
67.93 13.668 02-Sep-2005 10:03:00
68.43 13.67 02-Sep-2005 10:18:00
% Get duration from the start of each year and the year for grouping.
t.Dur = t.Time - dateshift(t.Time,"start","year");
t.Dur.Format = 'd';
t.Yr = year(t.Time);
head(t)
ans =
8×5 table
Var3 Var4 Time Dur Yr
_____ ______ ____________________ ___________ ____
65.11 13.666 02-Sep-2005 08:33:00 244.36 days 2005
65.27 13.668 02-Sep-2005 08:48:00 244.37 days 2005
65.6 13.669 02-Sep-2005 09:03:00 244.38 days 2005
66.1 13.669 02-Sep-2005 09:18:00 244.39 days 2005
66.93 13.667 02-Sep-2005 09:33:00 244.4 days 2005
67.43 13.669 02-Sep-2005 09:48:00 244.41 days 2005
67.93 13.668 02-Sep-2005 10:03:00 244.42 days 2005
68.43 13.67 02-Sep-2005 10:18:00 244.43 days 2005
hold on
rowfun(@(y1,D) plot(D,y1,'.'),t,'InputVariables',["Var3","Dur"],"GroupingVariables","Yr")
hold off
legend(string(unique(t.Yr)))
Results in the following figure.

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by