reading csv file into matrices

조회 수: 8 (최근 30일)
Pawan G
Pawan G 2019년 4월 11일
댓글: Walter Roberson 2019년 4월 15일
I want to read a .csv file into matricies (n*8). The csv file is semicolon seperated and decimal is comma (German format). In the beginning,the csvfile has statements but i am only interested from a11 to end. Could anyone help me to read this file. thanks in advance.

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 12일
filename = '270219etc.CSV';
S = fileread(filename);
NLpos = find(S == sprintf('\n'));;
S(1:NLpos(10)) = []; %delete first 10 lines
S(S==',') = '.';
fmt = repmat('%f', 1, 8);
data = cell2mat( textscan(S, fmt, 'Delimiter', ';'));
  댓글 수: 2
Pawan G
Pawan G 2019년 4월 15일
Hello Walter, could please explain me what does the line 3 in the code NLpos does? Thank you
Walter Roberson
Walter Roberson 2019년 4월 15일
NLpos is the position of all of the newlines in the input file. Indexing at 10 gives you the position of the end of the 10th line of input. You then remove everything from the beginning to there which removes the first 10 lines from the string.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by