在matlab中将表合并在一起

时间:2016-07-09 08:14:46

标签: matlab merge

如何将两个表合并在一起?

表1:

var ball: Ball!
ball = Ball(imageNamed:"colorBall.png")

表2:

LastName     Age    Weight    Smoker
__________    ___    ______    ______

'Smith'       38     176       true  
'Johnson'     43     163       false 
'Williams'    38     131       false 

成:

LastName     Age    Weight    Smoker
__________    ___    ______    ______
'Jones'       40     133       false 
'Brown'       49     119       false 

1 个答案:

答案 0 :(得分:2)

您可以使用以下方式执行此操作:

   Complete_Table=[Table1;
                   Table2]

完整代码: -

LastName = {'Smith';'Johnson';'Williams'};
Age = [38;43;38];
Weight = [176;163;131];
Smoker=logical([1;0;0]);
Table1 = table(LastName,Age,Weight,Smoker)

%Overwriting
LastName = {'Jones';'Brown'};
Age = [40;49];
Weight = [133;119];
Smoker=logical([0;0]);
Table2 = table(LastName,Age,Weight,Smoker)

Complete_Table=[Table1;
                Table2]

<强>输出: -

Table1 = 

     LastName     Age    Weight    Smoker
    __________    ___    ______    ______

    'Smith'       38     176       true  
    'Johnson'     43     163       false 
    'Williams'    38     131       false 


Table2 = 

    LastName    Age    Weight    Smoker
    ________    ___    ______    ______

    'Jones'     40     133       false 
    'Brown'     49     119       false 


Complete_Table = 

     LastName     Age    Weight    Smoker
    __________    ___    ______    ______

    'Smith'       38     176       true  
    'Johnson'     43     163       false 
    'Williams'    38     131       false 
    'Jones'       40     133       false 
    'Brown'       49     119       false