Borrar filtros
Borrar filtros

Create Dataset Container from CSV file

1 visualización (últimos 30 días)
Patrick Saegesser
Patrick Saegesser el 4 de En. de 2012
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?

Respuestas (2)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by