I want to convert the large datetime data into double format.

9 ビュー (過去 30 日間)
Khunsha
Khunsha 2024 年 9 月 12 日
編集済み: Stephen23 2024 年 9 月 12 日
I used datenum command, but its changing the value. The code and the values are attached below. Here TimestampHide is the data from an excel sheet.
MATLAB Code:
>> T=TimestampHide;
>> T.Format = 'yyyy-MM-dd HH:mm:ss.SSS';
>> Z=datenum(T);
The value of Z
  6 件のコメント
Steven Lord
Steven Lord 2024 年 9 月 12 日
You can call plot with a datetime array and a numeric array as inputs and it should just work.
x = 1:10;
dt = datetime('today') + days(x);
y = x.^2;
plot(dt, y, 'o-')
If you were trying to create multiple plots at once, that's one case where the data type matters. You can't put two plots that have different types of x data or different types of y data on the same axes, but that makes sense IMO. If I wanted to plot one plot that was dt on the X axis and y on the Y axis and another where x was on the X axis and y on the Y axis, what would the X axis labels be? Numbers or dates? We don't allow that workflow because of that consideration, as you can see from the error message below.
figure
plot(dt, y, 'o-', x, y, 'x:') % not going to work
Error using plot
Data inputs must match the axis configuration. A numeric axis must have numeric data inputs or data inputs which can be converted to double.
Stephen23
Stephen23 2024 年 9 月 12 日
編集済み: Stephen23 2024 年 9 月 12 日
"Because I want to plot a graph between time and power. Where power is in double as it contains only numeric values"
time = datetime(2024,1:12,1);
power = rand(1,12);
plot(time,power)

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

回答 (1 件)

dpb
dpb 2024 年 9 月 12 日
datenum is/has been deprecated; use datetime instead.
datenum doesn't have the precision of a datetime but the values above will be the same in double precision as the datetime values; you just aren't displaying all the significant digits with the default format option; try
datestr(Z(1:10))
and you will see the string values.
Show what your next step(s) is(are) as to why you think you should convert to datenum and somebody is bound to come along and provide the way to accomplish that goal with the datetime and/or duration classes instead.

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by