convert array string data in array serial number
3 ビュー (過去 30 日間)
古いコメントを表示
this example clarify my problem
>> size(B)
ans =
463628 1
>> B(1)
ans =
"01/01/2008"
>> datenum(B(1,:),'dd/mm/yyyy')
ans =
733408
>> datenum(B,'dd/mm/yyyy')
Error using datenum
DATENUM failed.
Caused by:
Error using dtstr2dtnummx
Failed to convert from text to date number.
i can convert the single string but not the array of strings
回答 (1 件)
Steven Lord
2023 年 5 月 23 日
Unless you're using an older release where it is not available I strongly recommend you use datetime instead of serial date numbers. Note I've changed your B slightly to make it clear that datetime is importing it correctly, not confusing the day and month information.
B = "02/03/2008";
dt = datetime(B, "InputFormat", "dd/MM/yyyy")
With a datetime array a lot of operations are easier and easier to interpret than with a list of date numbers. As an example, what's the day after dt?
nextDay = dt + days(1)
3 件のコメント
Stephen23
2023 年 5 月 23 日
編集済み: Stephen23
2023 年 5 月 23 日
"i've problem to use it"
It will work when you read and follow the DATETIME documentation or the example that Steve Lord showed you. Why did you change the syntax to something completely different?
S = "01/01/2008";
D = datetime(S, 'InputFormat','dd/MM/yyyy')
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!