Potential bug related to readtable's "VariableNamingRule"
50 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 20 Août 2021
It is a bug or limitation up through R2021a, that when you use 'Format' the only acceptable other option is 'FileType'.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!