![Case.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/206114/Case.png)
How to plot time and date (x-axis) on predicted model?
1 次查看(过去 30 天)
显示 更早的评论
I want to display time and date as shown in figure 1.After training the model i get the predicted values.The data file(.xlsx) is also attached.I want to plot Actual and Predicted values along with time on x-axis.I tried below code but didnt worked
table1=readtable('ResultsA.xlsx');
X=('Date')
Y=('Actual')
K=('Pred')
plot(table1.(X),table1.(Y));
hold on
t1=datetime(2016,11,19,04,21,0); %'dd.MM.yyyy HH:mm:ss'
t2=datetime(2016,11,20,18,00,0);
xlim([t1 t2])
plot(YPred)
hold off
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/204742/image.png)
0 个评论
采纳的回答
Naman Bhaia
2019-2-27
Hey Ali,
I tried running your code and with minimal change I got the date as the X- axis labels. Check if this is what you were looking for.
![Case.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/206114/Case.png)
table1=readtable('ResultsA.xlsx');
X=('Date');
Y=('Actual');
K=('Pred');
plot(table1.(X),table1.(Y),'b');
hold on
plot(table1.(X),table1.(K),'r');
t1=datetime(2016,11,19,04,21,0); %'dd.MM.yyyy HH:mm:ss'
t2=datetime(2016,11,20,18,00,0);
xlim([t1 t2])
hold off
3 个评论
Peter Perkins
2019-3-11
First thing is that you probabvly want a timetable, not just a table.
Given that,
plot(tt.Time,tt.X)
That's it. I don't know what the variables in your timetable would be called, but that's the idea.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!