how to create a time series from an excel data sheet containing hourly load in 1095 rows and 23 columns. no date or time in the excel data file.
2 views (last 30 days)
Show older comments
So I have this file containing data in 1095 rows corresponding to each day for three years and 24 columns corresponding to each hour of the day. I want to create a time series from the data.
load_data = xlsread('loadthree.xlsx');
start_date = datetime(2018,1,1);
hourly_increment = hours(1);
datetime_vec = start_date:hourly_increment:start_date+hours(size(load_data,1)-1);
load_vec = reshape(load_data, [], 1);
load_ts = timeseries(load_vec, datetime_vec, 'Name', 'Load Data');
%gives me the error "Error using timeseries/init
The second argument must be either the time vector or the time series name."
0 Comments
Answers (1)
chicken vector
on 20 Apr 2023
Edited: chicken vector
on 20 Apr 2023
According to the documentation, timeseries has to be either a scalar or a vector of scalars, therefore you can't use datetime.
This should be close to what you want:
% Input data:
load_data = xlsread('loadthree.xlsx');
start_date = datetime(2018,1,1);
load_vec = reshape(load_data, [], 1); % Or load_data(:)
% Time vector:
datetime_vec = 1:length(load_vec);
% Timeseries:
load_ts = timeseries(load_vec, datetime_vec, 'Name', 'Load Data');
load_ts.TimeInfo.Units = 'hour';
load_ts.TimeInfo.startDate = start_date;
load_ts.plot
0 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!