Putting Timetables Together to Create One Large Table
Show older comments
Hi,
I have a code. And I want to put the columns of timetables sequentially.
For instance, in my code produces these timetables tt5, tt11, tt17, tt23, tt29, tt36, tt41, tt47, tt53, tt59. They represent the years 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, and 2019, respectively.
Following the last row of tt5, I want the first row of tt11 to begin. Then following the last row of tt11, I want the first row of tt17 to begin. In this way, there creates one large table, with the data running straight from 2010 thru 2019.
I would appreciate any help. Thank you.
6 Comments
dpb
on 24 Jun 2020
- Don't build specific table variable names with numeric subscripts -- use array or cell array to be able to reference variables programmatically.
- Just build the table you have in mind from the git-go instead of making up all the intermediaries -- you have to read the various data to produce the various years of data anyway, just add to the one master table.
CMatlabWold
on 24 Jun 2020
dpb
on 24 Jun 2020
Yuck... :)
%2010
tt0 = readtable('BackupByZipCode1.xlsx');
tt1=table2timetable(tt0)
...
t = datetime(2010,1,1):caldays(1):datetime(2010,12,31);
...
%2011
tt6 = readtable('BackupByZipCode1.xlsx');
tt7=table2timetable(tt6)
...
t0 = datetime(2011,1,1):caldays(1):datetime(2011,12,31);
...
All is identical excepting for constants that can be coded as variables in a loop...there's no need for anything but one piece of code.
Unless the above is run in pieces and either the file is changed externally or the location in which the code is executed is different, then they're all using the identical data besides.
If the sections are using different copies of the file, then either externally rename them by year to be able to store in one common subdirectory or define an input table to specify where each is located.
Alternatively, just mung on the above and build the output table as an explicit catenation of each of the previous onto a global name.
CMatlabWold
on 24 Jun 2020
dpb
on 24 Jun 2020
t=[];
...
t=[t;tt5];
...
t=[t;tt11];
...
t=[t;tt17];
...
Or, you can just string 'em all out in the end.
Realistically, the whole thing ought to be trashed and rewritten...
CMatlabWold
on 25 Jun 2020
Answers (0)
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!