Combining multiple CSV's from a list of csv pairs
1 次查看(过去 30 天)
显示 更早的评论
Thank you in advance for any help on this. I am not sure where to even start. I have a .csv which shows pairings of file names something like this, but with 1,000+ filepaths:
'C:File1.csv', 'C:File2.csv',
'C:File3.csv', 'C:File4.csv'
Each row in the .csv contains 2 .csv filepaths that are meant to go together. Is it possible to horizontally concatenate the data from each pair outlined in the "pairing .csv" into a new .csv?
0 个评论
回答(1 个)
Jon
2022-6-30
编辑:Jon
2022-6-30
So for each row in the original "pairings.csv" you want to create a new .csv file, let's say for the 893rd row you would call this file out893.csv. The contents of this file would be created by reading in some matrix of values from each of the two files paths on the line, and horizontally concatenating them. You could do this as follows:
% read in the "pairing file"
pairings = readcell('pairings.csv','Delimiter',',');
% determine number of pairings
numPair = size(pairings,1);
% loop through pairings
for k = 1:numPair
% read in the data for each pair
% store in cell array since we don't know dimensions of the data to be
% read
data = cell(1,2); % preallocate cell to hold data
for j = 1:2
data{j} = readmatrix(pairings{k,j});
end
% now horizontally concatenate the data and write to the output file
outdat = horzcat(data{:,:});
outfile = "out"+num2str(k)+".csv";
writematrix(outdat,outfile)
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!