Importing a Table :: [Variables are been modified by Matlab]
Mostra commenti meno recenti
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 Commenti
Steven Lord
il 28 Apr 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
il 28 Apr 2016
Modificato: Image Analyst
il 28 Apr 2016
Walter Roberson
il 28 Apr 2016
Would it be practical to post the spreadsheet, or at least an initial portion of it?
Tejas Sonavane
il 28 Apr 2016
Modificato: Tejas Sonavane
il 28 Apr 2016
Tejas Sonavane
il 28 Apr 2016
Risposta accettata
Più risposte (1)
Bill Tubbs
il 12 Ott 2021
Modificato: Bill Tubbs
il 12 Ott 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 Commenti
Steven Lord
il 12 Ott 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
il 12 Ott 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{:}
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!