combining 4 csv files with and without headers
Mostra commenti meno recenti
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 Commenti
Adam Danz
il 27 Lug 2021
It sounds like you're working with timetables but it's unclear how you'd like the tables to be combined. Providing a short example may help.
Terry Yin
il 27 Lug 2021
Adam Danz
il 27 Lug 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.
Terry Yin
il 27 Lug 2021
Risposte (1)
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,:)
1 Commento
Terry Yin
il 28 Lug 2021
Categorie
Scopri di più su Simulink in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!