MATLAB Answers

How I can read a CSV file with header?

190 views (last 30 days)
Hildo
Hildo on 18 Jun 2015
Answered: Hildo on 25 Nov 2016
How I can read one CSV file with header, semicolon to separate the column and coma to float point? One example is annex. I try use the importdata, csvread and dlmread.

  1 Comment

Star Strider
Star Strider on 18 Jun 2015
Use the xlsread function if you have Excel.

Sign in to comment.

Accepted Answer

Hildo
Hildo on 25 Nov 2016
The better way was use the textscan function with ";" delimiter and after replace the "," by "." before the conversion of string to number.
fileID = fopen(filename,'r');
startRow = 10;
dataArray = textscan(fileID,'%s%s%s',inf,'Delimiter',';',...
'HeaderLines', startRow-1,'ReturnOnError', false);
fclose(fileID);
dataArray{1,2} = strrep(dataArray{1,2},',','.');
dataArray{1,3} = strrep(dataArray{1,3},',','.');

  0 Comments

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 20 Jun 2015
[a,b,c]=xlsread('PV-20150616.csv')
out=b(8:end,:)

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products