MATLAB: How to copy data from one timetable to another

MATLABtabletimetabletimetables

Hi all,
I have three timetables (called Tmin, Tmax, Prec) with daily meteorological variables at two measurement sites (Site 1 and Site 2; I will come back to Site 3 in a moment). The data are from 1st July 2018 to now. Here an example of the Prec timetable:
353×3 timetable
time Site_1 Site_2 Site_3
____________________ ______ ______ ____
01-Jun-2018 00:00:00 0.2 0.2 NaN
02-Jun-2018 00:00:00 0 0 NaN
03-Jun-2018 00:00:00 0 0 NaN
...
I'm trying to add data from a public weather station (Site 3, currently all NaNs) for the same period. These data are available online in monthly csv files which I import in a loop into monthly timetables:
30×3 timetable
Date MinimumTemperature__C_ MaximumTemperature__C_ Rainfall_mm_
__________ ______________________ ______________________ ____________
2018-06-01 4.1 13.3 0
2018-06-02 3.5 13.6 0.2
2018-06-03 4.3 13.8 0
What I'm trying to do is to copy Site 3 data from each monthly timetable into a respective row in column 3 of my main timetables (Tmin, Tmax, Prec).
1) Is there a simple function to do that?
2) Is it a problem that the date format isn't the same? If so, how can I change it?
Many thanks in advance for help!

Best Answer

Is there a simple function to do that?
Is it a problem that the date format isn't the same?
As long as they are in datetime format, it shouldn't be a problem.
There should be a way to specify that you want to merge the rainfall column of the second timetable (TT2) with the site_3 column of the first timetable (TT1) but after a brief search I haven't found that method (please leave comments if anyone finds it!). Alternatively you can:
  1. remove the unnecessary columns from TT2
  2. change the name of the rainfall column to "Site_3"
  3. remove the "Site_3" column from TT1
  4. Merge the two cleaned-up time tables.
That would look something like this:
% Remove columns in 2nd timetable that shouldn't be merged with table 1
TT2clean = removevars(TT2,{'MinimumTemperature__C_','MaximumTemperature__C_'});
% Rename Rainfall column to "Site_3"
TT2.Properties.VariableNames = strrep(TT2.Properties.VariableNames,'Rainfall_mm_','Site_3');
% Remove Site_3 from first timetable
TT1clean = removevars(TT1,'Site_3');
% Synchronize timetables
TT = synchronize(TT1clean,TT2clean);