How to read only numerical data from irregular .csv file

조회 수: 13 (최근 30일)
Juan Makaka
Juan Makaka 2019년 3월 12일
댓글: Juan Makaka 2019년 3월 13일
I have a .csv file with header and numerical data. I just want to get the numerical data starting in row 6 and col 2. I am trying to use textscan but I failed to get the data. This is my code and one of my files. Any idea for that ?. Thanks.
fid = fopen('00_IR_00327 - T0R1P2.csv','rt');
NumHeaders = 5;
NumDataLines = 240;
ColNum = 320;
fmt =['%*s', repmat('%f',1,ColNum-1),'\r\n'];
data = textscan(fid, fmt, NumDataLines, 'HeaderLines', NumHeaders,'Delimiter',',');
fclose(fid);

답변 (1개)

Akira Agata
Akira Agata 2019년 3월 13일
Since your csv file was saved as a 16-bit text, it's a little bit difficult to use textscan to read data correctly.
I think another possible way is using xlsread function. How about the following?
[~,~,c] = xlsread('00_IR_00327 - T0R1P2.csv');
data = [];
for kk = 6:numel(c)
str = strsplit(c{kk},',');
data = [data;str2double(str)];
end
% Delete 1st column and the last empty column
data(:,[1 end]) = [];

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by