How to read only numerical data from irregular .csv file

13 vues (au cours des 30 derniers jours)
Juan Makaka
Juan Makaka le 12 Mar 2019
Commenté : Juan Makaka le 13 Mar 2019
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);

Réponses (1)

Akira Agata
Akira Agata le 13 Mar 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]) = [];

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by