Plot Day of Year with Time
조회 수: 3 (최근 30일)
이전 댓글 표시
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
Dyuman Joshi
2022년 11월 23일
The values in the headers are varying for each time, it will only give you vertical lines (with the way you want to plot).
If you want a continuous graph as the picture you attached, you will need a continuous data.
Also there's a lot of data missing in the file attached.
답변 (1개)
Seth Furman
2022년 12월 5일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!