How to change the date-format of an existing file ?

16 ビュー (過去 30 日間)
Haron Shaker
Haron Shaker 2021 年 1 月 18 日
コメント済み: Walter Roberson 2021 年 1 月 27 日
Dear community,
Applying the 'readcell'-function to one of my existing files (here: .xls and .xlsx- files) I get the following error:
'Error using readcell (line 151)
Could not recognize the date/time format of '15-März-2019'. You can specify a format using the 'InputFormat' parameter. If the date/time text contains day, month, or time zone names in a language foreign to the 'en_US' locale, those might not be recognized. You can specify a different locale using the 'Locale' parameter.'
How can I change the it? Please consider the attachment.

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 1 月 18 日
datetime('15-März-2019', 'Locale', 'de')
ans = datetime
15-Mar-2019
So use readcell() with 'Locale', 'de'
  6 件のコメント
Haron Shaker
Haron Shaker 2021 年 1 月 27 日
編集済み: Haron Shaker 2021 年 1 月 27 日
Thanks!
You're right, in this cutout it is not defined.
I still get an error:
Error using datetime (line 546)
Wrong number of arguments.
Error in trytorun (line 27)
xlsData(:,2) = cell2mat( datetime(xlsData{:,2}, 'Locale', 'de') );
By the way: Does it make a difference in using 'readcell' or 'readtable'?
Walter Roberson
Walter Roberson 2021 年 1 月 27 日
readtable returns a table object, whereas readcell returns a cell array in which each entry is a separate cell, so Yes, it does matter.
Using {:,2} would be wrong for readcell but I think it should work for readtable as it should return the second variable as a single argument.

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

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by