Plotting Timetable in Matlab

조회 수: 243 (최근 30일)
Anders Vigen
Anders Vigen 2021년 2월 19일
답변: cui,xingxing 2024년 7월 3일
load_demand=readtable("Demand_timeseries_1hourResolution.xlsx");
TR=table2timetable(load_demand);
Time=TR({'05-05-2020','05-06-2020 00:00:00'},:);
T = timetable2table(Time)
x=T{2:end,1}
y=T{2:end,3}
plot(x,y)
I am trying to plot my timetable, but it will only plot a single point for it. So instead of plotting the whole data series for 'Time' it only plots for the first point. I tried converting it to an array but that didn't work out too well. Hopefully somebody can help me

채택된 답변

Anders Vigen
Anders Vigen 2021년 2월 23일

추가 답변 (2개)

Duncan Po
Duncan Po 2021년 2월 19일
The line:
Time=TR({'05-05-2020','05-06-2020 00:00:00'},:);
only extracts two rows from TR. So Time only has two rows. Then when you define x and y, the first row is discarded, so x and y are scalar. That's the reason only one point is plotted.
If you want the entire series, just use the entire TR instead of extracting only two rows.
  댓글 수: 17
Walter Roberson
Walter Roberson 2021년 2월 21일
The representation of hours turned out to be strange :(
load_demand = readtable("Demand_timeseries_1hourResolution.xlsx");
h = cellfun(@(S) sscanf(S, '%d', 1), load_demand.Hours);
load_demand.Time = load_demand.Date + hours(h);
mask = isbetween(load_demand{:, 1}, datetime('2020-05-05'), datetime('2020-05-06')-minutes(1));
x = load_demand.Time(mask);
y = load_demand{mask,3};
plot(x, y);
Anders Vigen
Anders Vigen 2021년 2월 23일
@Walter Roberson you are a genius! It worked completely as it should. Thank you very much for the dedication on this issue!

댓글을 달려면 로그인하십시오.


cui,xingxing
cui,xingxing 2024년 7월 3일
Here I give a Example:
tt = datetime+years(1:10); % 比如从现在时间开始,连续十年时间点
y = rand(10,1);
TT = timetable(tt',y)
TT = 10x1 timetable
Time y ____________________ ________ 03-Jul-2025 07:22:39 0.73968 03-Jul-2026 13:11:51 0.65843 03-Jul-2027 19:01:03 0.83686 03-Jul-2028 00:50:15 0.87343 03-Jul-2029 06:39:27 0.074945 03-Jul-2030 12:28:39 0.71392 03-Jul-2031 18:17:51 0.67515 03-Jul-2032 00:07:03 0.21619 03-Jul-2033 05:56:15 0.28457 03-Jul-2034 11:45:27 0.080194
plot(TT.Time,y,LineWidth=2)

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by