I need to write a code to import multiple csv files, changing delimiter and decimal standard...

41 Ansichten (letzte 30 Tage)
Hi guys,
I need to import multiple .csv files. Nonetheless, all my tries are going wrong: the file delimiter (even though it is .CSV, the delimiter is the semicolon (;), and the decimal is the comma (,). Please, I need help. I was doing:
P = 'fullpath';
S = dir(fullfile(P,'*.csv'));
for k = 1:numel(S)
F = fullfile(P,S(k).name);
S(k).data = csvread(F);
end
But I have the message:
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> (creator description)
Error in csvread (line 48)
m=dlmread(filename, ',', r, c);
Can someone help me, please? Many thanks in advance!

Akzeptierte Antwort

Stephen23
Stephen23 am 27 Okt. 2021
Use READMATRIX and set the Delimiter and DecimalSeparator to values that suit your file.
  5 Kommentare
Stephen23
Stephen23 am 28 Okt. 2021
Replace
readmatrix(F)
with
readmatrix(F, 'Delimiter',';', 'DecimalSeparator',',')
If you have any more difficulties, please upload your CSV file by clicking on the paperclip button.
Paulo Henrique Março
Paulo Henrique Março am 28 Okt. 2021
Hi Stephen
Fantastic!
Now the problem is completely solved.
You saved my week!
Thank you a lot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by