필터 지우기
필터 지우기

How do you get rid of the VariableNamingRule warning when you do want it set to modify ?

조회 수: 122 (최근 30일)
Hi, I have the following code:
opts = detectImportOptions(fullfile(file_B_path, file_B_name)); % Detects import of table
opts = setvartype(opts, 'ID', 'string'); % Sets ID to string datatype
opts = setvartype(opts, 'RvCCompliance', 'string'); % Sets RvC Compliance to string datatype
---> opts.VariableNamingRule = 'modify';
file_B = readtable(fullfile(file_B_path, file_B_name),opts); % Imports table
and I keep getting the following warning:
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before
creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
I know that variablenamingrule is set to modify, in fact, I want it to be set to modify. Why wont adding the line with the pointer get rid of this messege ?

채택된 답변

dpb
dpb 2023년 6월 16일
It's annoying to be constantly nagged, agreed. But, setting it explicitly doesn't affect whether it is generated or not as you've discovered.
But, while a pain to have to do every time use readtable, it's relatively simple to fix...
opts = detectImportOptions(fullfile(file_B_path, file_B_name)); % Detects import of table
opts = setvartype(opts, 'ID', 'string'); % Sets ID to string datatype
opts = setvartype(opts, 'RvCCompliance', 'string'); % Sets RvC Compliance to string datatype
w=warning('off','MATLAB:table:ModifiedAndSavedVarnames'); % turn off annoying warning, save state
file_B = readtable(fullfile(file_B_path, file_B_name),opts); % Imports table
warning(w); % reset warning level
Since 'modify' is the default state for the name preservation property, it doesn't need to be set in the options struct and makes no difference if it is (as you've seen).
  댓글 수: 3
Peter Perkins
Peter Perkins 2023년 7월 17일
Santiago, this warning is a known issue that is left over from the days before VariableNamingRule. For now, the work-around is what dpb suggests.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by