How to read only numerical data from irregular .csv file
13 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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 Center および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!