Create Dataset Container from CSV file
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (2)
owr
am 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.
0 Kommentare
Patrick Saegesser
am 5 Jan. 2012
1 Kommentar
Peter Perkins
am 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'.
Siehe auch
Kategorien
Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!