csvread: Trouble reading 'Numeric' field from file
33 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Guilherme T Silva
am 5 Jan. 2018
Beantwortet: Walter Roberson
am 5 Jan. 2018
Hi,
I'm trying to read the attached csv file, but both csvread is having trouble to parse through line 8010 of the second column (Input) of the file, where the values have a $ concatenated. This is the error message I get:
>> a = csvread('test.csv',2,0)
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 8011, field number 1) ==> $\n
Error in csvread (line 48)
m=dlmread(filename, ',', r, c);
I tried using readtable as well, but the Input column characters would be stored as cells, and converting that column to a matrix didn't work.
My end goal here would be loading the file to a table, while replacing the invalid characters with either NaN or zero. What's the best way to achieve it? Thanks!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 5 Jan. 2018
datacell = textscan( regexprep( fileread('test.csv'), '\$', '0' ), '%f%f', 'delimiter', ',', 'HeaderLines', 1);
Duration = datacell{1};
Input = datacell{1};
YourTable = table(Duration, Input);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!