Nonstandard input date format into readstruct function?

조회 수: 6 (최근 30일)
Martin Ryba
Martin Ryba 2022년 12월 7일
댓글: Martin Ryba 2022년 12월 12일
I have some XML files from another system and I want to be able to process the data therein. The readstruct function mostly fits the bill, but all the date/time fields get filled with "NaT" values because the input format isn't what datetime() expects and the Locale options aren't good enough. In particular, the input fomat is 'HH:mm:ss MM/dd/yyyy' which is I guess backwards from what datetime wants. The best option would be to add a "DateInputFormat" keyword to readstruct() that got passed as "InputFormat" to datetime(). Any other options?

채택된 답변

Jeremy Hughes
Jeremy Hughes 2022년 12월 12일
I believe this is a bug. I've created a bug report internally. Thanks.

추가 답변 (1개)

Aylin
Aylin 2022년 12월 12일
Thanks for reporting this.
There is an undocumented "DetectTypes" parameter on readstruct. Enabling this will read all XML nodes as either strings or missing values. This might help work around the issue for you.
>> type ans.xml
<A>
<B>11:12:13 10/15/2022</B>
</A>
>> S = readstruct("ans.xml", DetectTypes=false)
S =
struct with fields:
B: "11:12:13 10/15/2022"
Please note that this is an undocumented parameter, and may change in a future release.
  댓글 수: 1
Martin Ryba
Martin Ryba 2022년 12월 12일
Thanks, I ended up grabbing xml2struct from the File Exchange which does somthing similar, and pulling out and parsing the fields I needed by hand (giving datetime the InputFormat from the ICD used, and str2double most other places).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by