Concatenate Tables with one variable having different lengths

36 views (last 30 days)
I am trying to concatentate two tables within which the first variable is a string of different lengths, between tables.
T1 = table('Alpha', 33, 6); % Create first table
T2 = table('DoubleAlpha', 36, 8); % Create second table
TT = vertcat(T1,T2); % Concatenate tables
This gives an error:
Could not concatenate the table variable 'Var1' using VERTCAT.
Caused by:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Is there an additional argument or way to initialize an empty table to permit vertcat?

Accepted Answer

Walter Roberson
Walter Roberson on 16 Jun 2019
Edited: Walter Roberson on 16 Jun 2019
Later versions than yours reject your input syntax because of ambiguity about options versus inputs.
T1 = table({'Alpha'}, 33, 6); % Create first table
T2 = table({'DoubleAlpha'}, 36, 8); % Create second table
TT = vertcat(T1,T2); % Concatenate tables
The error message for your syntax in modern versions is
You might have intended to create a one-row table with the character vector 'Alpha' as one of its variables. To store text data in a table, use a string array or a cell array of character vectors rather than character arrays. Alternatively, create a cell array with one row, and convert that to a table using CELL2TABLE.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!