Import CSV data into Matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to import data CSV using MATLAB, with patient_1(1).Data, as a following:
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
Walter Roberson
2018년 7월 4일
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.
채택된 답변
Walter Roberson
2018년 7월 4일
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
Walter Roberson
2018년 7월 16일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!