Borrar filtros
Borrar filtros

join a specific column from csv 2 to csv 1

2 visualizaciones (últimos 30 días)
Ant376
Ant376 el 6 de Sept. de 2021
Comentada: Ant376 el 7 de Sept. de 2021
i have a folder containing 10 files, a1.csv, a2.csv ... a5.csv and b1.csv, b2.csv ... b5.csv
I am trying to create a new csv file with the columns from .csv A and the second column from .csv B
folderPath = '/Volumes/Extreme SSD/ERA5/csv/';
for y = 1:5
yStr = num2str(y);
A = csvread([folderPath,'a',yStr,'.csv']);
B = csvread([folderPath,'b',yStr,'.csv']);
C = [A,B(2)];
csvfilename = 'c'+string(y)+'.csv';
csvwrite(csvfilename,C);
end
I keep getting the message:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
with the above, what am i doing wrong?
edit to add:
When i use
C=[A,B];
there is no error

Respuesta aceptada

Dave B
Dave B el 7 de Sept. de 2021
Assuming your CSV files are shaped appropriately, you probably want:
C = [A B(:,2)]
B(2) refers to the second element in B, B(:,2) refers to the second column in B.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by