append several csv files into one
古いコメントを表示
Hello to all!
I am trying to append some csv files into one file using the following code:
csv1 = csvread('2011_basehourlycurves_demand.csv');
csv2 = csvread('2012_basehourlycurves_demand.csv');
allCsv = [csv1;csv2];
csvwrite('combined_csv', allCsv);
However, when I try to call my data it appears the following error:
Error using dlmread
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==>
Which I guess is because one of my varible/columns is composed by a categorical variable.
How can I fix this error? I tried using textscan, but It was not working.
Thank you in advance!
4 件のコメント
dpb
2020 年 1 月 20 日
W/O the file to look at, it's just a guess...are there headerlines?
You can try readtable, but for real help you'll have to show us the file structure...
If the task is to just do a blind copy/catenate, send that job to the OS COPY command...of course, you'll then still presumably need to read the result so we're back to the starting point--"show us the file(s)".
Dinesh Yadav
2020 年 1 月 23 日
As dpb commented show us your files so we can help you.
Walter Roberson
2020 年 1 月 23 日
Never use csvread for content that contains text.
Andrew Janke
2020 年 1 月 31 日
Are you doing power/electricity market analysis? Always interesting to see another Energy person in the Matlab space!
採用された回答
その他の回答 (1 件)
Andrew Janke
2020 年 1 月 31 日
If you're using a newer version of Matlab, you probably want to use readtable instead of csvread. Don't forget the file extension for your output file.
t1 = readtable('2011_basehourlycurves_demand.csv');
t2 = readtable('2012_basehourlycurves_demand.csv');
allDAta = [t1;t2];
writetable('combined_csv.csv', allData);
カテゴリ
ヘルプ センター および File Exchange で Workspace Variables and MAT Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!