필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how to read many csvfile?

조회 수: 1 (최근 30일)
suyeon kim
suyeon kim 2018년 2월 2일
마감: MATLAB Answer Bot 2021년 8월 20일
i want to read many csvfiles and run it at once. how to read and run many csvfiles?
i use for loop, dlmread. but there are not worked.
someone help me.thank you.

답변 (1개)

Prajith Chilummula
Prajith Chilummula 2018년 2월 8일
Hi suryeon kim,
dlmread() reads numeric data into matrix.
For example (files used in the code are attached),
fileNamesArray= {1.csv,2.csv};
data = cell(numel(fileNamesArray),2);
data(:,1) = regexprep(fileNames, '.csv','');
for i = 1: numel(fileNamesArray)
data{i,2} = dlmread(fileNamesArray{i});
end
Please refer this document for further information:
https://www.mathworks.com/help/releases/R2017b/matlab/ref/dlmread.html
The normal recommendation for dealing with csv files having data in any type is to use
textscan(), but textscan() is harder to deal with when there are string fields with missing values.
Textscan reads the data into a cell array and it matches the data in the file with the formatSpec.
Example:
fileNamesArray= {1.csv,2.csv};
for i = 1: numel(fileNamesArray)
f = fopen(fileNamesArray(i));
X = textscan(f, %s%s%s’, 'Delimiter', ',', 'HeaderLines', 1);
fclose(f);
end
Please refer this document for further information:
https://www.mathworks.com/help/releases/R2017b/matlab/ref/textscan.html
Hope this answers the query.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!