Importdata incorrectly reads csv file

조회 수: 7 (최근 30일)
PSBclocktower
PSBclocktower 2020년 8월 13일
답변: Cris LaPierre 2020년 8월 13일
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
Walter Roberson
Walter Roberson 2020년 8월 13일
are any of the columns text?
have you tried using readtable instead?
dpb
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
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.

카테고리

Help CenterFile 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!

Translated by