combining 4 csv files with and without headers
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have 4 .csv files that is generated from an equipment that I am using. One of the csv files has 4 columns with a heading, and the other 3 csv files have between 2-3 columns without heading. I would like to use a column from each csv file as a reference as to where the values should be placed. The file with 4 colums is the "master" file with a timestamp for the duration of the experment and the other three csv files have unique timestamps that corrrespond to somewhere in the "master" file.
Is this something that is possilbe to do in Matlab?
4 commentaires
Adam Danz
le 27 Juil 2021
No, but you could attach files to a comment or, better yet, provide a quick sample of just a few rows from each of the 3 csv files and a description of how the data should be merged. Once the problem is clearly defined my bet is that the solution will be staightforward.
Réponses (1)
Adam Danz
le 27 Juil 2021
You can use outerjoin to join the first 2 tables into 1 table. It's not entirely clear how you're indexing the 3rd table into the first two but it sounds like you want the closest time stamps in table 3 to the time stamps in table 2. These two steps are demonstracted below using the demo data you provided.
% Create 3 tables
d1 = [ 0 13084.4048 7 0.02967622
1 13084.4429 7 0.02961321
2 13084.481 7 0.02967732 ];
T1 = array2table(d1, 'VariableNames', {'FC','timestamp','Flags','Region'})
d2 = [ 0 48786598
1 48786634.2
2 48786672.8
3 48786710.3 ];
T2 = array2table(d2, 'VariableNames', {'FC','time_ms'})
d3 = { 'Space' 49154818.5
'Space' 49210956.1
'Space' 49218482.5
'Space' 49253519.6};
T3 = cell2table(d3, 'variablenames', {'Key','time_ms'})
% Join tables 1 and 2
T12 = outerjoin(T1, T2, 'keys','FC','MergeKeys',true)
% Find the row of the closest time stamples in T12 to the time stamps in T3
[~, minidx] = min(abs(T12.time_ms - T3.time_ms'))
T12(minidx,:)
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!