Importing a Table :: [Variables are been modified by Matlab]
Afficher commentaires plus anciens
Hi I have recently started using matlab. I am trying to import a spreadsheet as a table and some of my variables [Colum Names] get modified when I look at them using T.Properties.Variablenames. So I checked the function genvalidnames which is apparently responsible for changing the "non-matlab" variable names to standard matlab variable names. My Column names in the Spreadsheet all start with a character, have only underscores and are not longer than nameslength which i checked is 63. Still I get the modified names. Any idea why this will be happening.
5 commentaires
Steven Lord
le 28 Avr 2016
What specific names were modified?
Were any of the names in your spreadsheet duplicates?
Were any of the names that were modified MATLAB keywords (as listed by the iskeyword function?)
Tejas Sonavane
le 28 Avr 2016
Modifié(e) : Image Analyst
le 28 Avr 2016
Walter Roberson
le 28 Avr 2016
Would it be practical to post the spreadsheet, or at least an initial portion of it?
Tejas Sonavane
le 28 Avr 2016
Modifié(e) : Tejas Sonavane
le 28 Avr 2016
Tejas Sonavane
le 28 Avr 2016
Réponse acceptée
Plus de réponses (1)
Bill Tubbs
le 12 Oct 2021
Modifié(e) : Bill Tubbs
le 12 Oct 2021
The answer by Steven Lord didn't work for me. I got this error:
Error using readtable (line 198)
Unknown Parameter 'VariableNamingRule'.
readtable(filename,'PreserveVariableNames',true)
3 commentaires
Steven Lord
le 12 Oct 2021
The PreserveVariableNames property (which could only take on values true and false) was replaced in release R2020b with the "VariableNamingRule" name-value pair (which had 'preserve' and 'modify' as valid values) as stated in the Release Notes. That's the change I mentioned in square brackets in my comment on Image Analyst's accepted answer.
Bill Tubbs
le 12 Oct 2021
Ah, sorry I missed that. Thanks. I guess I will have to update my code next year when I upgrade MATLAB...
You could future proof your code now while it's fresh in your mind. Use verLessThan to determine if the MATLAB installation is older than release R2020b. Use PreserveVariableNames if it is and VariableNamingRule if it is not.
if verLessThan('matlab', '9.9') % 20b
parametersToUse = {'PreserveVariableNames', true};
else
parametersToUse = {'VariableNamingRule', 'preserve'};
end
fprintf("The option is %s and the value you have selected is %s.\n", ...
string(parametersToUse))
You can use parametersToUse as a comma-separated list.
parametersToUse{:}
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!