Help using csvread to combine and reduce CSV files; Error using dlmread (line 147) Mismatch between file and format character vector.

1 次查看(过去 30 天)
I have 47 CSV files of 60005 lines that look a bit like this
I want to create a matlab script to load them all into one matrix, reduce them, then save to xlsx like this, but it doesn't work.
clear all; clc;
files = 47; % number of CSV files
rows = 60005; % rows in each CSV file
totrows = rows*files; %number of fiels times number of rows
maxallowedrows = 1048576; %max allowed .xlsx rows
frequency = totrows/maxallowedrows; %frequency i need to reduce by
frequency = ceil(frequency); %round up frequency to integer
CSV = [1,2,3,4,5,6,7,8,9,10,11,12,13,13,14]; % create CSV matrix for file
for file = 1:files % for every file
fnum = num2str(file); % convert file number to string
filename = (['THERMAL_VTC6_',fnum,'.csv']); %create file name
CSV = [CSV; csvread(filename,5,1,[5 1 rows 14])]% load file and add to bottom of matrix
end % end loop
for mycycle = 1:totalrows
if isinteger(mycycle/frequency)
for A = 1:14
XLSXfileadd(1,A) = CSV(mycycle,A); % sample every line that is divisible by frequency
end % end loop
if mycycle ~= frequency
XLSXfile = [XLSXfile; XLSXfileadd]; % if not first file then add to bottom matrix
else
XLSXfile = XLSXfileadd; % if first line then create matrix, do not add as it doesnt exist yet
end
end % end loop
end % end loop
I get the error
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 7) ==> /09/15
09:31:18,100,3.5273,2.0007,0.0001,0.0002,0.0001,StepRunning,27.8992\n
Error in csvread (line 50)
m=dlmread(filename, ',', r, c, rng);
Error in CSV_Combine (line 12)
CSV = [CSV; csvread(filename,5,1,[5 1 rows 14])]% load file and add to bottom of matrix
I believe it's something to do with the text columns in my file not working with CSVread
Thank you in advance for your help
Ben

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by