Plot Day of Year with Time
7 views (last 30 days)
Show older comments
This question was flagged by Star Strider
I'm trying to plot data with the headers 1-8 as my y-axis and the day of year with time in the x-axis, to show something similar as the "Example.png".
2 Comments
Answers (1)
Seth Furman
on 5 Dec 2022
Importing the data
Normally, we could use readtimetable to import Data.csv, but The Time variable has an unusual format, so we have to do some extra work to import Data.csv as a timetable.
t = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1203593/Data.csv",TextType="string");
t.Properties.VariableNames = t{1,:};
t = t(2:end,:);
t = addvars(t,double(extractBefore(t.Time,4)),Before="1",NewVariableNames="DayOfYear");
t.Time = duration(extractAfter(t.Time,4));
tt = table2timetable(t)
Presumably, we have a particular year for which the data were measured. Assuming that year was 2022, we can add datetime(2022,1,1) to our day-of-year to get the date, which we can then add to the time of day.
Note: We must use caldays instead of days, because not every day in a year is exactly 24 hours.
tt2 = tt;
tt2.Time = tt2.Time + datetime(2022,1,1) + caldays(tt2.DayOfYear) % OR caldays(tt2.DayOfYear-1)
Remove rows with missing data.
tt2 = rmmissing(tt2)
Visualize the timetable
It's not immediately clear to me how you'd like to visualize the data, but stackedplot is a good starting place for visualizing timetables.
stackedplot(tt2)
0 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!