How to plot time and date (x-axis) on predicted model?

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

 採用された回答

Naman Bhaia
Naman Bhaia 2019 年 2 月 27 日

0 投票

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
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 件のコメント

Ali
Ali 2019 年 3 月 4 日
Thank you for your answer.It works.Apart from reading excel(.xlsx) file,how can we plot time series data directly from table matrix.For instance:
load data.mat % table having 14000x14
data2=data(:,3);
Time_date=data(:,1);
y=table2array(data2);
.....................
how to plot?
.....................
plot (time and data)
Peter Perkins
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.
Ali
Ali 2019 年 3 月 12 日
Thanks peter

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

Ali
2019 年 2 月 19 日

コメント済み:

Ali
2019 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by