Merging different size csv files
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to make data analysis + import into excel much easier. I have 3 different data types, call them data1, data2, data3. I have 99 csv files of each. data1(1) is related to data2(1) and data3(1), etc. I was hoping to merge all files together. I'd also be happy to just merge all files of each type together, so I have 1 csv file for data1, 1 file for data2, etc.
data1 and data2 are row vectors, while data3 is matrices. Every entry can be a different size (though none are meaningfully large). My current code:
for ii=1:99
sgnFile = sprintf('sgn_%d.csv',ii);
areaFile = sprintf('area_%d.csv',ii);
centFile = sprintf('centroids_%d.csv',ii);
csvwrite(sgnFile, measurements{1,ii});
csvwrite(areaFile, measurements{2,ii});
csvwrite(centFile, measurements{3,ii});
end
My data was originally in a cell array called "measurements", and was 3x99. For the life of me, I can't figure out how to make this process more efficient - there are many similar questions that I can't get to work for my own code. Thanks!
0 comentarios
Respuestas (1)
Nanda Gupta
el 8 de Jun. de 2018
Based on my understanding, I am assuming that you have a cell array "measurements" of size 3X99 and you have 99 CSV files with of the same with the 3 data types. and would like to have 3 CSV files instead of 99 by merging all the data of the same data type into one CSV file. If you still have the "measurements" cell array with you, one way would be to use "cat" function or just the vector operations to concatenate the columns and then write it into the CSV file. You can use the for-loop for doing this and then write the concatenated data at once onto your CSV file. This would improve the performance by decreasing the overhead for multiple access time to your CSV.
There are multiple ways you can concatenate the column vectors of your cell arrays, the following links might help you get started with it:
0 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!