I want to concate two tables vertically.the table has no variable name.how can I do that?
5 views (last 30 days)
Show older comments
size of one table is 2*4(contains number) and another is 1*4(contains single charcter),bt ineed a table of 3*4 combining these two table.how?
3 Comments
KL
on 28 Nov 2017
Take a minute and describe your problem. Your description is nowhere close to your post's title.
Accepted Answer
More Answers (2)
Jan
on 28 Nov 2017
T1 = array2table([1,2,3,4; 5,6,7,8]);
T2 = array2table('ABCD')
C12 = [table2cell(T1); table2cell(T2)];
T12 = array2table(C12)
Mh, I'm not convinced. There should be a way without a conversion to a cell. But:
T12 = [T1; T2]
sets the values of the numbers to empty matrices.
2 Comments
Jan
on 28 Nov 2017
What exactly is "too much"? You can use the profiler to find out, where the time is spent.
Peter Perkins
on 29 Nov 2017
The problem here is that the requirement of two rows that are numbers and one row that is text is exactly the opposite orientation that tables are designed for. So Jan's solution creates what is essentially one 3x4 cell array, with numbers in some cells and text in others, while cvklpstunc's solution turns the numbers into text.
I'm guessing that this is all about display, not about creating a table for manipulating data. If you were storing those data, you'd want to do it like this:
>> x = [1 2 3 4;6 7 3 4];
>> y = ['A' 'B' 'C' 'D'];
>> t = table(x(1,:)', x(2,:)', y')
t =
4×3 table
Var1 Var2 Var3
____ ____ ____
1 6 A
2 7 B
3 3 C
4 4 D
Jan's solution ends up displaying something like
T12 =
3×4 table
C121 C122 C123 C124
____ ____ ____ ____
[1] [2] [3] [4]
[5] [6] [7] [8]
'A' 'B' 'C' 'D'
which probably is not desirable for display.
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!