Matt Griffin
Matt Griffin

Reputation: 95

How can I merge tables with different numbers of rows?

I'm currently trying to create a signal process diagram in MATLAB. In order to do this, I have 3 tables that I would like to plot different signals from that would require merging in order to be plotted on the same graph (but separated out so to see the signals separately).

So far I have tried:

% The variables below are examples of the tables that contain 
% the variables I would like to plot.

s1 = table(data1.Time, data1.Var1); % This is a 8067x51 table
s2 = table(data2.Time, data2.Var2); % This is a 2016x51 table
s3 = table(data3.Time, data3.Var3); % This is a 8065x51 table

% This gives an error of 'must contain same amount of rows.'
S = [s1, s2, s3];

% This puts the three tables into a cell array
S = {s1, s2, s3};

Any suggestions welcome.

Upvotes: 1

Views: 1787

Answers (1)

gnovice
gnovice

Reputation: 125864

You were close. You just need to concatenate your tables vertically instead of horizontally:

S = [s1; s2; s3];
% Or in functional form
S = vertcat(s1, s2, s3);

Note that this only works if all the tables have the same number of variables (i.e. columns).

Upvotes: 1

Related Questions