Convert date from number to format in matllab

I have original time and date format as mentioned below:
2/17/2020 9:48:18 AM
I did forecasting using this , and after forecasting output date in the plot appears in number format like :
43878.4085416667
How can i convert it back to original date and time format ?

9 Comments

How did you do the forecasting with it?
Did you convert the date/time t numeric using datenum() ? If so, only do that if the forecasting routines do not support datetime objects, and otherwise use datetime() .
yes, i converted using datenum()
Data=readtable('data.xlsx');
testdates = Data{1:end,1};
date_num = datenum(testdates);
date_num2 = datenum(testdates)+table2array(Data(1:end,2))./(24*3600);
then i used below code to plot it :
figure
plot(out)
hold on
plot(in,'.-')
hold off
but it appears like serial numbers :i want to convert it to date and time format :i tried the below code but unable to plot since it is character array(pic attached) :If i convert it to double again it becomes NAN since it has string values:
o=datestr(in);
S = double(out);
S1=datestr(S);
figure
plot(out)
hold on
plot(in,'.-')
hold off
date_num2 = testdates + seconds(Data{:,2});
Now if possible use date_num2 in the forecasting, and plot with
plot(date_num2, in)
thank you for your response.It worked for input date ,but didnt work for the output
out is date value generated after forecasting , and how can i convert this output back to date time format .
How are you generating the date value from forecasting ?
The values near 43878.4085416667 suggest to me,
datetime(43878.4085416667, 'convertfrom', 'excel')
ans = datetime
17-Feb-2020 09:48:18
but why are you getting Excel dates at all???
This is the output i am getting . i need to convert it back to date time format
i tried converting it to character array using below code ,
S = double(out);
S1=datestr(S);
but still not able to plot

Sign in to comment.

 Accepted Answer

outd = datetime(out, 'convertfrom', 'excel');
plot(outd)

10 Comments

thank you .It worked
Your code should be changed so that it does not produce Excel date numbers from the forecast. However, you are not being cooperative in identifying how it is getting Excel date numbers as output values, so I stopped caring.
NN
NN on 31 Jan 2021
Edited: NN on 31 Jan 2021
:-(
I will definitly change the code .But please advise how to do it .i am not an expert in programming , thats why
The first step would be to describe how you are currently doing the forecasting. Which I already asked about twice before.
LSTM forecasting
The error is on line 7, character #11.
sorry , i didnt understand
This is the information we, as outside observers, have so far:
  1. You have a datetime() vector named in
  2. Your results from your forecasting is named out
  3. Your results are in Excel date numbers
  4. You are using lstm forecasting.
(4) tells us that you must have created layers, and called trainNetwork(), and probably called predictAndUpdateState() https://www.mathworks.com/help/deeplearning/ug/time-series-forecasting-using-deep-learning.html
However, it does not tell us what you passed to trainNetwork(), and it does not tell us what layers you used.
So... we need to read your mind to figure that out. And when I read your mind, and your memory of what code you wrote, I figured out that your bug is in character #11 of line 7 of your code.
I was right, the bug is in character #11 of line 7 of your code. (Prove me wrong!)

Sign in to comment.

More Answers (0)

Tags

Asked:

NN
on 31 Jan 2021

Edited:

on 5 Feb 2021

Community Treasure Hunt

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

Start Hunting!