How do I delimit (and replace) multiple CSV files in a loop?
이전 댓글 표시
I have several CSV files that contain data separated by commas (x, y, z) in column A. The headers are strings with parentheses ("XXXXXXXXXX (XX)", "YYYYYYYYYY (YYY)", "ZZZZZZZZZ"), while the data (x, y, z) are numerical values. Usually, I would highlight the A column and delimit the columns in Excel in order to separate my data into three separate columns in order to analyze. However, I have a lot of these files now, and I was wondering if I could write a for loop to read these files, delimit, replace the text in the original file in the correct number of columns, and save the new file again.
I tried csvread, but it's having trouble reading the commas. A sample CSV file is in the attachments. Thanks for any help in advance.
댓글 수: 4
Walter Roberson
2018년 10월 4일
To confirm: you want to split each .csv into three separate files? If so then what names should the three new files have relative to the old file?
Stephen23
2018년 10월 4일
@Alex Chen: please upload a sample file by clicking the paperclip button.
Alex Chen
2018년 10월 4일
채택된 답변
추가 답변 (1개)
KSSV
2018년 10월 4일
files = dir('*.csv') ;
N = length(files) ;
for i = 1:N
[data,txt,raw] = xlsread(files(i).name) ;
% data are your numbers..do wjat you want
end
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!