# Plotting Timetable in Matlab

227 vues (au cours des 30 derniers jours)
Anders Vigen le 19 Fév 2021
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
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Anders Vigen le 23 Fév 2021
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Plus de réponses (1)

Duncan Po le 19 Fév 2021
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 commentairesAfficher 15 commentaires plus anciensMasquer 15 commentaires plus anciens
Walter Roberson le 21 Fév 2021
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 le 23 Fév 2021
@Walter Roberson you are a genius! It worked completely as it should. Thank you very much for the dedication on this issue!

Connectez-vous pour commenter.

### Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by