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!