Merge two columns in timetable?
Afficher commentaires plus anciens
I'm merging a number of .csv files into one big timetable. Each of the .csv files represents one day's data from a radio station - one column for frequency, one column for amplitude. I'd like for each station to have its own frequency column and its own amplitude column in the final timetable, but since I am adding the columns to the timetable one file at a time using the synchronize() function I wind up with multiple columns for each.
Here's the for loop I'm generating to create the timetable. The original files are named analysis_XXXXXX - Callsign.csv, where XXXXX is the date and Callsign is the station identifier.
for j = 1:length(Files)
% Extract date and call from filename.
meta = extractBefore(FileNames(j), '.csv')
meta = split(meta, ' - ')
date_recorded = char(extractAfter(meta(1), 'analysis_'))
day = str2num([date_recorded(1:2); date_recorded(3:4); date_recorded(5:6)])
start = datetime([2000+day(1) day(2) day(3) 0 0 0]);
Call = meta(2);
foo = readtable(FileNames(j), 'Range','A:E');
foo.Properties.VariableNames = [{'UTC'},{'Freq'},{'FreqErr'},{'Vpk'},{'dBV_Vpk_'}];
foo=table2timetable(foo);
foo.UTC = foo.UTC + start;
foo.Properties.VariableNames = strcat(foo.Properties.VariableNames, '-', Call);
if exist('baz')
baz = synchronize(foo, baz);
else
baz = foo;
end
end
This results in columns named, say, Freq-Station1_foo which has values for Day 1 of data collection and NaNs for Day 2, next to Freq-Station1_baz which has values for Day 2 and NaNs for Day 1. Is there a way I can merge them?
2 commentaires
Cris LaPierre
le 2 Oct 2020
It would be easier to offer suggestions if you could share a few of your files. You can use the paperclip icon to attach them to your post.
Kristina Collins
le 6 Déc 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!