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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by