Plotting Timetable in Matlab
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
Duncan Po
2021년 2월 19일
0 개 추천
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
Anders Vigen
2021년 2월 20일
Walter Roberson
2021년 2월 20일
https://www.mathworks.com/help/matlab/ref/timerange.html#d122e1343230
Anders Vigen
2021년 2월 20일
Walter Roberson
2021년 2월 20일
load_demand = readtable("Demand_timeseries_1hourResolution.xlsx");
TR = table2timetable(load_demand);
subset = timerange(datetime('05-05-2020', 'InputFormat', 'MM-dd-yyyy'),datetime('05-06-2020 00:00:00', 'InputFormat', 'MM-dd-yyyy HH:mm:ss'));
Time = TR(subset,:);
T = timetable2table(Time)
x=T{2:end,1}
y=T{2:end,3}
plot(x,y)
By the way, why are you skipping the first row?
Note: using timerange would be a lot easier if you were using a standard way of representing the dates.
subset = timerange('2020-05-05', '2020-05-06')
The mess with calling datetime() with 'InputFormat' is only needed because month-day-year is not one of the recognized international time formats.
Anders Vigen
2021년 2월 20일
편집: Anders Vigen
2021년 2월 20일
Should be okay provided that you have more than one hour of data being selected.
x = datetime('2020-05-05 00:00'):hours(1):datetime('2020-05-05 23:00');
y = rand(1,length(x));
plot(x, y)
Anders Vigen
2021년 2월 20일
Walter Roberson
2021년 2월 20일
load_demand = readtable("Demand_timeseries_1hourResolution.xlsx");
mask = isbetween(load_demand.Time, 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
2021년 2월 21일
Walter Roberson
2021년 2월 21일
load_demand = readtable("Demand_timeseries_1hourResolution.xlsx");
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);
Walter Roberson
2021년 2월 21일
편집: Walter Roberson
2021년 2월 21일
I do not have your file so I was guessing about the variable name based on some of your other comments in other posts.
Anders Vigen
2021년 2월 21일
Walter Roberson
2021년 2월 21일
load_demand = readtable("Demand_timeseries_1hourResolution.xlsx");
load_demand.Time = load_demand.Date + hours(load_demand.Hours);
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);
Walter Roberson
2021년 2월 21일
This could have been resolved days ago if you have attached a sample file.
Anders Vigen
2021년 2월 21일
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
2021년 2월 23일
Hi, @Anders Vigen
Here I give a Example:
tt = datetime+years(1:10); % 比如从现在时间开始,连续十年时间点
y = rand(10,1);
TT = timetable(tt',y)
plot(TT.Time,y,LineWidth=2)
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

