MATLAB Answers

Plotting of yearly data.

6 views (last 30 days)
Zunaira Akmal
Zunaira Akmal on 10 Dec 2019
Edited: per isakson on 13 Dec 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 Comments

Show 1 older comment
Zunaira Akmal
Zunaira Akmal on 10 Dec 2019
https://drive.google.com/file/d/104maiPEgppPd2zM_feXl-4M0_c4O6Mwi/view?usp=drivesdk here is the link of the dataset. i want to plot one complete year data(last column data) and then on the same graph i want to plot another one and so on upto 15 years. i want january-December on the x-axis.
dpb
dpb on 10 Dec 2019
Attach a .mat or .txt file here...we don't go to external sites.

Sign in to comment.

Answers (1)

Eric Sofen
Eric Sofen on 13 Dec 2019
Edited: per isakson on 13 Dec 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.

  0 Comments

Sign in to comment.

Sign in to answer this question.