Create Dataset Container from CSV file
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
owr
il 4 Gen 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 Commenti
Patrick Saegesser
il 5 Gen 2012
1 Commento
Peter Perkins
il 5 Gen 2012
Patrick, the above is not a comma-separated file. Presumably, those are tabs in there, so you want to use 'Delimiter','tab'.
Vedere anche
Categorie
Scopri di più su Data Import from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!