Convert date from number to format in matllab
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2021-1-31
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() .
NN
2021-1-31
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);
NN
2021-1-31
编辑:NN
2021-1-31
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/504903/image.png)
o=datestr(in);
S = double(out);
S1=datestr(S);
figure
plot(out)
hold on
plot(in,'.-')
hold off
Walter Roberson
2021-1-31
date_num2 = testdates + seconds(Data{:,2});
Now if possible use date_num2 in the forecasting, and plot with
plot(date_num2, in)
NN
2021-1-31
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 .
Walter Roberson
2021-1-31
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???
NN
2021-1-31
i tried converting it to character array using below code ,
S = double(out);
S1=datestr(S);
but still not able to plot
采纳的回答
Walter Roberson
2021-1-31
outd = datetime(out, 'convertfrom', 'excel');
plot(outd)
10 个评论
Walter Roberson
2021-1-31
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.
Walter Roberson
2021-1-31
The first step would be to describe how you are currently doing the forecasting. Which I already asked about twice before.
Walter Roberson
2021-2-1
This is the information we, as outside observers, have so far:
- You have a datetime() vector named in
- Your results from your forecasting is named out
- Your results are in Excel date numbers
- 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.
NN
2021-2-5
so sorry ,
i tried to do LSTM in the same way as in https://www.mathworks.com/help/deeplearning/ug/time-series-forecasting-using-deep-learning.html
Walter Roberson
2021-2-5
编辑:Walter Roberson
2021-2-5
I was right, the bug is in character #11 of line 7 of your code. (Prove me wrong!)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Objects 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)