trouble importing multiple .csv files with strings in first row
Show older comments
Hi all,
I wrote below MATLAB code to import multiple csv files named B00Pr1-0001 to B00Pr1-n in a folder and save them in a cell:
l=dir('B00Pr1-*.csv'); % list .csv files
n=length(l);
data=cell(1,n);
for i=1:n
data(i)=csvread(l(i).name);
end
The problem is that my csv files look like below (its actual size is bigger) and have strings in the first row so I cannot use csvread because I get the following error:
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==>
nodenumber, x-coordinate, y-coordinate,velocity-magnitude, x-velocity,
y-velocity, temperature\n
nodenumber x-coordinate y-coordinate velocity-magnitude x-velocity y-velocity temperature
1 0.00E+00 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.98E+01
2 1.25E-04 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.93E+01
3 2.50E-04 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.87E+01
4 3.75E-04 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.80E+01
5 5.00E-04 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.74E+01
6 6.25E-04 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.67E+01
7 7.50E-04 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.60E+01
8 8.75E-04 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.54E+01
9 1.00E-03 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.47E+01
10 1.12E-03 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.40E+01
11 1.25E-03 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.34E+01
12 1.37E-03 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.27E+01
13 1.50E-03 0.00E+00 0.00E+00 0.00E+00 0.00E+00 9.21E+01
my goal is loading all csv files data do some math on the data and save them in a matrix. What do you suggest to solve this problem?
thank you in adavance!
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!