1

I have 2 cell arrays (both of the same size 30*1) where all their elements are timetables. Lets assume that the first element (timetable) from the first cell array is the following:

timeStamps = datetime([2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5; 

2017 3 5]);

Volume = [51 101 150 200 254 330 35 40]';

Price= [40 35 40 25 40 35 10 25]';
T= table(timeStamps, Volume, Price)
A= table2timetable(T)

and the first element (timetable) from the second cell array is:

timeStamps = datetime([2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5; 2017 3 5]);

w = [22 10 3 4 4 3 3 4]';

Q= [40 1 2 3 40 335 120 2]';
M= table(timeStamps, w, Q)
B= table2timetable(M)

How can I create a new cell array (of size 30*1) such that their elements are composed by the append of the variables of the first two timetables. In this case, the first element (or timetable) from this new cell array will look like:

 N= table(timeStamps,Volume,Price, w, Q)

  R= table2timetable(N)

Sorry if I do not defined the cell arrays but I find it useless to get the info that I want to know.

Thanks a lot for all your help!

Antoine Fa
  • 61
  • 5
  • that is a great asked a question! (Sorry, the answer seems to be kind of trivial^^) – max Apr 01 '20 at 15:28

1 Answers1

0

concatenate simply both tables: [A,B]

So if you have two cells C1 and C2, loop through them and to the following

for i = length(C1)
   C1{i} = [C1{i},C2{i}];  
end
max
  • 3,915
  • 2
  • 9
  • 25
  • Thank you @max, I used your code and I got the following note 'All tables in the bracketed expression must have the same number of rows.' I think is because even when the size for each timetable that will be append is the same for each element, it is not among elements. Any idea how to correct it? Thank you! – Antoine Fa Apr 01 '20 at 16:26
  • The timestamps must be the same in time tables if you want to concatenate them. A quick fix would be `[A,timetable2table(B,'ConvertRowTimes',false)]` but be aware that you loose all time information of `B` in this case and that you simply assume that its rows have the same timestamp as `A` – max Apr 01 '20 at 16:32