Skip reading headers in MATLAB

I had a similar question. but now I'm trying to read .txt files in MATLAB. My problem is with the headers. Many times, due to errors, the system overwrites the headers in the middle of the file, and then MATLAB cannot read the file. Is there any way to skip this? I know that I can skip reading some characters if I know what that character is.

here is the code i am using.

[c,pathc]=uigetfile({'*.txt'},'Select the data','V:\data');     
file=[pathc c];    
data= dlmread(file, ',', 1,4);    

this way I can let the user select the file. My files are huge [86400 125] so naturally it has 125 header fields or more depends on the files.

thank

Since the files are so large that I can’t copy, but its format is in the format

  day      time    col1    col2 col3 col4 ...............................
  2/3/2010  0:10    3.4    4.5   5.6  4.4 ...............................   
..................................................................    
..................................................................   

etc.

+3
source share
2

DLMREAD . , . , DLMREAD 2 :

data = dlmread(file, ' ', 1,2); 

, IMPORTDATA DLMREAD:

A = importdata(file, ' ', 1);
dt = datenum(A.textdata(2:end,1),'mm/dd/yyyy');
tm = datenum(A.textdata(2:end,2),'HH:MM');
data = A.data;

. DATESTR.

+3

, textscan. , . double. 'str2double' NaN , - , NaN.

:

%# find and open file
[c,pathc]=uigetfile({'*.txt'},'Select the data','V:\data'); 
file=[pathc c];
fid = fopen(file);

%# read all text
strData = textscan(fid,'%s%s%s%s%s%s','Delimiter',','); 

%# close the file again
fclose(fid);

%# catenate, b/c textscan returns a column of cells for each column in the data
strData = cat(2,strData{:}); 

%# convert cols 3:6 to double
doubleData = str2double(strData(:,3:end));

%# find header rows. headerRows is a logical array
headerRowsL = all(isnan(doubleData),2);

%# since I guess you know what the headers are, you can just remove the header rows
dateAndTimeCell = strData(~headerRowsL,1:2);
dataArray = doubleData(~headerRowsL,:);

%# and you're ready to start working with your data 
+2

Source: https://habr.com/ru/post/1740058/


All Articles