Filter löschen
Filter löschen

Combining 12 .csv Files

33 Ansichten (letzte 30 Tage)
Rachel Cox
Rachel Cox am 16 Nov. 2022
Beantwortet: Aritra am 21 Nov. 2022
Helllo, I'm trying to combine 12 .csv files into one. They all have the same column titles but are 12 seperate months. We want to be able to plot all of the months in order on one graph.
  1 Kommentar
Stephen23
Stephen23 am 16 Nov. 2022
What have you tried so far?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Aritra
Aritra am 21 Nov. 2022
Hi Rachel,
As per my understanding, you are trying to combine the data from multiple ‘.csv’ files into a single ‘.csv’ file.To solve this issue, you can use the readmatrix(filename) function for reading column-oriented data from ‘.csv’ files. Next the horzcat(A,B) function can be used for concatenating the matrices horizontally.
Assuming the files are all in the same folder and you have changed your directory to there, try something like:
files = dir('*.csv'); % Get list of files
out = readmatrix(files(1).name,delimitedTextImportOptions('DataLines',[1,Inf])); % First file
for ii = 2:numel(files)
new = readmatrix(files(ii).name,delimitedTextImportOptions('DataLines',[1,Inf])); % Read the nth file
out = horzcat(out,new(:,:)); % Horizontal Concatenation
end
writecell(out,'Output.csv');

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by