Plot Day of Year with Time
6 ビュー (過去 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!