Create Dataset Container from CSV file

2 views (last 30 days)
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?

Answers (2)

owr
owr on 4 Jan 2012
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 on 5 Jan 2012
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 Comment
Peter Perkins
Peter Perkins on 5 Jan 2012
Patrick, the above is not a comma-separated file. Presumably, those are tabs in there, so you want to use 'Delimiter','tab'.

Sign in to comment.

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!