Importdata incorrectly reads csv file
18 次查看(过去 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!