How to remove warning message when we read csv file?
    36 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Arshey Dhangekar
 am 1 Okt. 2021
  
    
    
    
    
    Kommentiert: Gabriel
 am 9 Jan. 2023
            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
clc
clear all
d=dir('i*.csv'); 
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])  
        continue
    end        
    opts.DataLines = [nhdr+2 inf];
    opts.VariableNamesLine = nhdr+1;
    T{i} = readtable(d(i).name,opts);
end
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.
0 Kommentare
Akzeptierte Antwort
  Mathieu NOE
      
 am 1 Okt. 2021
        hello 
simply add this line at the start of your code :
warning off
3 Kommentare
  Bill Tubbs
      
 am 24 Mär. 2022
				For anyone still using R2019b this option was: "PreserveVariableNames", 1
  Gabriel
 am 9 Jan. 2023
				warning off
This is a very bad solution. It's like hitting a fly with a bomb.
every warning has an off switch that you can switch just it. 
use 
[msg,warnID] = lastwarn
to find the warning ID and then switch just this specific warning OFF using 
warning('off','MATLAB:table:ModifiedAndSavedVarnames')
or in general
warning('off',warnID)
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




