필터 지우기
필터 지우기

Create Dataset Container from CSV file

조회 수: 1 (최근 30일)
Patrick Saegesser
Patrick Saegesser 2012년 1월 4일
I want to create a dataset array from a .csv file where the first row is a string header and all other rows are numerical values. Size total dataset size is 38x50.
My code is:
IndexData = dataset('file','Test.csv',...
'Delimiter',',',...
'ReadObsNames','off');
However, when I run this I get a 0x1900 dataset array. Since this corresponds to the total number of cells in the csv, I'm pretty sure it either has to do with the csv formatting (there are spaces in some of the header strings which I would like to keep if there is a way to do so) or that I did not use a necessary parameter.
Any ideas where I went wrong?

답변 (2개)

owr
owr 2012년 1월 4일
I do this all the time with code similar to yours, so it is possible. Are there commas separating each header string? The spaces shouldnt be a problem, but the field names in the dataset array cannot have spaces (as of 2011A at least). The dataset array constructor should be able to deal with this though and will either remove the spaces or replace them with a hex equivalent.
I'd suggest making a very simple example in an XL spreadsheet and save the file to a csv. Try loading that to see if it works and then see what is different between your original file and the test file.
Good luck.

Patrick Saegesser
Patrick Saegesser 2012년 1월 5일
I just tried to do the same as laid out above (same code) with the following test array:
Date SetA SetB
40811 30 31
40812 40 62
40813 55 28
and it resulted in a 0x9 dataset container which looks empty in the variable editor.
I really don't know what's wrong. Is it possible that excel 2011 (mac) creates a different type of csv? I opened the it as a text file, the delimiter is comma. Are there any other possible differences that lead matlab to misread the file?
  댓글 수: 1
Peter Perkins
Peter Perkins 2012년 1월 5일
Patrick, the above is not a comma-separated file. Presumably, those are tabs in there, so you want to use 'Delimiter','tab'.

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

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by