How to plot forecasted data with corresponding dates

1 view (last 30 days)
I am trying to do ANN load forecasting. Finally, when I plot actual and modelled output, some problem is with the date. It shows a different waveform.I believe the problem is with formatting date and plotting data with respect to it.Please advice how to do date formatting correctly .
Date is read from 2019 , 9th month till 12th month(that is specified from 5834th raw till end
%reading date Data=readtable('2019_SysLoad.xlsx'); save 2019_SysLoad.mat Data testdates=Data((5834:end),1); %converting dates to array A = table2array(testdates); plot(datetime(A),target_test);
i am getting like this .
I am supposed to get like shown below with dates on x aixs:
Kindly advice .
Thanks in advance
  2 Comments
VBBV
VBBV on 25 Oct 2020
You can try using timetable and retime functions
% if true
% code
%end
tt = timetable(testdates,target_test)
DT = days(3);
Tnew = retime(tt,'regular,'linear','timestep',DT);
plot(Tnew.testdates,Tnew.target_test);

Sign in to comment.

Answers (2)

Cris LaPierre
Cris LaPierre on 25 Oct 2020
You simply have your X-Data be datetimes. The code you shared should work. Can you confirm that datetime(A) creates dates?
Here's a simple example:
d = datetime(2020,01,01):calmonths(1):datetime(2020,12,31);
data = rand(size(d));
plot(d,data)

Peter Perkins
Peter Perkins on 18 Nov 2020
This code snippet
Data=readtable('2019_SysLoad.xlsx');
testdates=Data((5834:end),1); %converting dates to array
A = table2array(testdates);
plot(datetime(A),target_test);
is unclear. It seems you are reading a spreadsheet into a table, getting a one-var table from that, converting that to the raw data, converting that to datetime, and plotting.
For one thing, this seems simpler:
Data=readtable('2019_SysLoad.xlsx');
A = Data.SomeVarName(5834:end); % or Data{5834:end,1} if you don't know the var name
plot(datetime(A),target_test);
I guess the first var in your table is, what, text timestamps? That's the only way I can make sense of datetime(A). In which case, I'd suggest working with a timetable, something like this:
tt = table2timetable(Data(:,2:end),'RowTimes',datetime(Data.SomeVarName))
I also have no idea what else is in Data, or indeed where target_test is coming from. It would seem logical that target_test would be extracted from Data.
So OK, you have a datetime and you plot you target_test against that, and you get a nice plot. But it seems like you are wanting to have a plot against some kind of elapsed time. I don't know where, say, 200 comes from. Maybe it's a number of elapsed days since ... something? They don't seem to be row numbers.
Try subtracting your origin datetime from A, and setting the resulting duration's format to 'd'.

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!