Potential bug related to readtable's "VariableNamingRule"

조회 수: 50 (최근 30일)
David Li
David Li 2021년 8월 20일
답변: Walter Roberson 2021년 8월 20일
According to Create table from file - MATLAB readtable (mathworks.com), 'VariableNamingRule' and 'preserve' is a valid name-value pair. However, this pair does NOT seem to be recognized when there is an existing name-value pair in the argument. That is,
inertialMagFieldDataTable = readtable('InertialMagFieldData_simplified.csv', 'VariableNamingRule', 'preserve')
does work, but
inertialMagFieldDataTable = readtable('InertialMagFieldData_simplified.csv', 'VariableNamingRule', 'preserve', 'Format', '%{dd MMM yyyy HH:mm:ss.SSS}D%f%f%f')
does NOT work (and gives the error "Invalid parameter name: VariableNamingRule").
Question 1: is that a bug on MATLAB's part?
So, as a result, I've had to do something like
opts = detectImportOptions('InertialMagFieldData_simplified.csv');
opts.VariableNamingRule = 'preserve';
opts = setvartype(opts, 'Time_UTCG_', 'datetime');
opts = setvaropts(opts, 'Time_UTCG_', 'InputFormat', 'dd MMM yyyy HH:mm:ss.SSS', 'DatetimeFormat', 'yyyy-MM-dd HH:mm:ss');
inertialMagFieldDataTable = readtable('InertialMagFieldData.csv', opts);
I feel like there should be a way to do what the five lines of code above do with only one or two lines of code, especially if the potential bug related to 'VariableNamingRule' is fixed.
Question 2: what's the most concise way to do it (including converting the output datetime format to 'yyyy-MM-dd HH:mm:ss')?

답변 (1개)

Walter Roberson
Walter Roberson 2021년 8월 20일
It is a bug or limitation up through R2021a, that when you use 'Format' the only acceptable other option is 'FileType'.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by