Importdata incorrectly reads csv file
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a csv file that I am trying to import using the "importdata" command. In the csv file, the headers begin on row 12, and there are several columns of cells containing data, that are separated by a single blank column (ex: 5 columns of data, then a blank column, then another 5 columns of data, then another blank column, and finally another 5 columns of data).
My original code was:
headerlinesIn=12;
delimiterIn=',';
OC=importdata(OrigFile,delimiterIn,headerlinesIn)
mydata=OC.data;
---
MATLAB does not throw an error, but when I look at the variable "mydata", it is a type double array containing only last 5 columns of data, not the data from the whole csv file. Do you have any suggestions? I'm sorry I cannot provide the content of the csv file for troubleshooting.
댓글 수: 2
dpb
2020년 8월 13일
편집: dpb
2020년 8월 13일
" I cannot provide the content of the csv file for troubleshooting. "
Well, hard to debug what we cannot see...but importdata isn't the most user-controllable option; it's designed to be easy for the user if things are regular and simple.
If you have missing data and particularly if there are mixed data types, try using detectimportoptions first and the importdata object it creates to control what fields are recognized and how are interpreted.
답변 (1개)
Cris LaPierre
2020년 8월 13일
Try importing your data interactively using the Import Tool. There, you can set data types, data ranges, etc. This video may be helpful for learning how to use it. You can also generate the code used to import the data from the Import Tool. This video on generating and reusing code created by the import tool shows you how.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!