How to read only numerical data from irregular .csv file
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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);
0 Kommentare
Antworten (1)
Akira Agata
am 13 Mär. 2019
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]) = [];
Siehe auch
Kategorien
Mehr zu Data Import and Export 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!