csvread file containing text

조회 수: 8 (최근 30일)
HD
HD 2016년 4월 28일
댓글: HD 2016년 4월 28일
Hi I have a CSV file as follow (it is only an example, the real file is much bigger)
text1 text2
numb1 numb2 text3 num3 num4 ...
numb5 numb6 text4 num7 num8 ...
. . .
. . .
. . .
the command M2 = csvread('Test.csv',1,3) works well to save the data after the text column.
I would like to save the first two column starting from the second row.
I tried : M = csvread('Test.csv',1,0,[1,0,2,1])
I have an error in reading the data (I assume because of the text in field 3): Trouble reading 'Numeric' field from file (row number 1, field number 3) ==>
Do you any suggestion please ?
Thank you in advance

채택된 답변

Stephen23
Stephen23 2016년 4월 28일
편집: Stephen23 2016년 4월 28일
The solution is very simple: use textscan instead. textscan works with files containing mixed (numeric and text) data, whereas the functions csvread and dlmread only read numeric data.
When you have this kind of task it is easy to browse the help documentation and find all of the file reading/writing functions listed:
and then you can read their descriptions, and pick the best one for your task.
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 4월 28일
C = textscan(fileID,'%f%f%*[^\n]');
The %*[^\n] will match everything up to the end of the line, and discard it.
HD
HD 2016년 4월 28일
it is working now .. thank you!!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by