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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by