readtable working differently for different files
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a bunch of spreadsheets which all have the same format. However, when I read them in, they appear differently...
folder=('H:\SoundTrap\Boats\Manual Vessel Detections');
d=dir(fullfile(folder,'*.csv'));
site=('Goat');
for i=1:height(d)
idx=contains(d(i).name,site);
if idx==1
out{i}=readtable(fullfile(folder,d(i).name));
end
end
For some reason, one of the files is read using a different delimeter? So the columns are incorrectly split. How can I rectify this? I have tried detect import options and 'Format' '%s%s%s' to no avail. Perhaps I am using these incorrectly though. The desired format is the one below:
댓글 수: 3
Stephen23
2021년 6월 8일
@Louise Wilson: please upload two or more sample flles (ones which import differently) by clicking the paperclip button.
채택된 답변
Walter Roberson
2021년 6월 8일
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/645435/001_GoatIsland_5100_manualVesselDetections.csv', 'delimiter', ',');
T1(1:10,:)
T2 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/645440/009_GoatIsland_5100_manualVesselDetections.csv', 'delimiter', ',');
T2(1:10,:)
The files are different: the second one has an extra empty field, and that throws off MATLAB into thinking maybe the delimiter is underscore.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!