Importing a Table :: [Variables are been modified by Matlab]
显示 更早的评论
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 个评论
Steven Lord
2016-4-28
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
2016-4-28
编辑:Image Analyst
2016-4-28
Walter Roberson
2016-4-28
Would it be practical to post the spreadsheet, or at least an initial portion of it?
Tejas Sonavane
2016-4-28
编辑:Tejas Sonavane
2016-4-28
Tejas Sonavane
2016-4-28
采纳的回答
更多回答(1 个)
Bill Tubbs
2021-10-12
编辑:Bill Tubbs
2021-10-12
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 个评论
Steven Lord
2021-10-12
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
2021-10-12
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{:}
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!