How to remove warning message when we read csv file?

조회 수: 27(최근 30일)
Arshey Dhangekar
Arshey Dhangekar 2021년 10월 1일
댓글: Steven Lord 2021년 10월 1일
When I try to read csv file warning message coming. I want to eliminate that message. Since I have more than 30 csv files 30 times warning messages popping. How can I remove all warning message. Here is my code
clear all
opts = detectImportOptions(d(1).name,"Delimiter",",");
T = {};
for i=1:numel(d)
fid = fopen(d(i).name,'r');
nhdr = 8 + cell2mat(textscan(fid,'Total Channels:%f',1,'HeaderLines',5,'Delimiter',','));
fid = fclose(fid);
if nhdr == 8 % skip no data in file cases if that occurs (dpb conjecture)
warning(['No data. Skipped file: ' d(i).name])
opts.DataLines = [nhdr+2 inf];
opts.VariableNamesLine = nhdr+1;
T{i} = readtable(d(i).name,opts);
And warning message
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.

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 10월 1일
simply add this line at the start of your code :
warning off
  댓글 수: 1
Steven Lord
Steven Lord 2021년 10월 1일
That's a very large hammer that could mask real problems in the code.
If you're okay with getting the original column headers I'd follow the instructions in the warning and modify the readtable call.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.

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

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by