How to plot forecasted data with corresponding dates

1 回表示 (過去 30 日間)
NN
NN 2020 年 10 月 25 日
回答済み: Peter Perkins 2020 年 11 月 18 日
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 件のコメント
VBBV
VBBV 2020 年 10 月 25 日
can you upload the sample data file ?
VBBV
VBBV 2020 年 10 月 25 日
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);

サインインしてコメントする。

回答 (2 件)

Cris LaPierre
Cris LaPierre 2020 年 10 月 25 日
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 2020 年 11 月 18 日
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'.

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by