Import CSV data into Matlab
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Agnes Palit
el 4 de Jul. de 2018
Editada: Agnes Palit
el 16 de Jul. de 2018
I am trying to import data CSV using MATLAB, with patient_1(1).Data, as a following:
![](/matlabcentral/answers/uploaded_files/124011/Screen%20Shot%202018-07-04%20at%2021.47.57.png)
to import I used this code:
filedir = '/Users/'; files1 = dir(fullfile(filedir, '*.csv')); numFiles1 = length(files1); for i = 1 : numFiles1 patient_1(i).Name = files1(i).name; patient_1(i).Data = readtable(fullfile(filedir,files1(i).name),'ReadVariableNames',false); % loads data end
But I got this warning and following error:
Warning: Unable to determine the format of the DURATION data. Try adding a format to the DURATION specifier. e.g. '%{hh:mm:ss}T'. > In table/readTextFile>textscanReadData (line 554) In table/readTextFile (line 225) In table.readFromFile (line 39) In readtable (line 197) In patient1 (line 23) Error using readtable (line 197) Unable to determine the format of the DURATION data. Try adding a format to the DURATION specifier. e.g. '%{hh:mm:ss}T'. Note: readtable detected the following parameters: 'Delimiter', ';', 'HeaderLines', 0, 'Format', '%q%q%T%q%q%T%T%f%f%q%q' Error in patient1 (line 23) patient_1(i).Data = readtable(fullfile(filedir,files1(i).name),'ReadVariableNames',false); % loads data
Can anyone help me to solve this problem?
4 comentarios
Walter Roberson
el 4 de Jul. de 2018
patient_1(i).Data = readtable(fullfile(filedir,files1(i).name), 'ReadVariableNames', true, 'HeaderLines', 1);
A small number of lines for the test file would be fine. I extracted some of the data from the image you posted but I am not encountering the message you are getting.
Respuesta aceptada
Walter Roberson
el 4 de Jul. de 2018
opt = detectImportOptions('EE_moderate.csv');
opt = setvartype(opt, [2 5], 'datetime');
opt = setvaropts(opt, [2 5], 'InputFormat', 'dd-MMM yyyy', 'DatetimeFormat', 'eee uuuu-MM-dd HH:mm:ss' );
...
T = readtable(fullfile(filedir,files1(i).name), opt);
T.date = T.date + T.time;
T.date_1 = T.date_1 + T.time_1;
patient_1(i).Data = T(:,[2 5 7:end]);
...
19 comentarios
Walter Roberson
el 16 de Jul. de 2018
Not all of your files have a field #10.
In the original file, field #10 contained percentages complete with the % character. detectImportOptions sees the % and figures that the entire field must be a character vector rather than a number. Doing the setvartype() is to force it to treat as a number, with the % character taken care of by way of the Suffixes option.
I think I asked you earlier what other special characters might occur in fields that you want treated as numeric.
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time 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!