Potential bug related to readtable's "VariableNamingRule"
50 次查看(过去 30 天)
显示 更早的评论
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')?
0 个评论
回答(1 个)
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'.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!