How do I add data from one table to another?

135 views (last 30 days)
Sid
Sid on 12 Aug 2022
Answered: Karim on 12 Aug 2022
I have two tables of different sizes.
Table 1 is of size 1x28
Table 2 is of size 6x28
First table consists of the varibale names and the second table consists of the values of those variables. How do I copy the values from the second table and paste them below the variable names in the first table?
Final table size should be 7x28
Thanks in advance for your support

Answers (1)

Karim
Karim on 12 Aug 2022
Hello, you can simply append the tables, see below for an example
Var1 = ["A";"B";"C";"D";"E"];
Var2 = [1;2;3;4;5];
Var3 = logical([1;0;1;0;1]);
Var4 = [10;20;30;40;50];
Var5 = rand(5,1);
T1 = table(Var1,Var2,Var3,Var4,Var5)
T1 = 5×5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ _____ ____ ________ "A" 1 true 10 0.009762 "B" 2 false 20 0.72771 "C" 3 true 30 0.93664 "D" 4 false 40 0.88622 "E" 5 true 50 0.3576
Var1 = ["F";"G";"H"];
Var2 = [6;7;8];
Var3 = logical([0;1;0]);
Var4 = [60;70;80];
Var5 = rand(3,1);
T2 = table(Var1,Var2,Var3,Var4,Var5)
T2 = 3×5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ _____ ____ _______ "F" 6 false 60 0.71311 "G" 7 true 70 0.56284 "H" 8 false 80 0.43647
% merge the tables
T = [T1;T2]
T = 8×5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ _____ ____ ________ "A" 1 true 10 0.009762 "B" 2 false 20 0.72771 "C" 3 true 30 0.93664 "D" 4 false 40 0.88622 "E" 5 true 50 0.3576 "F" 6 false 60 0.71311 "G" 7 true 70 0.56284 "H" 8 false 80 0.43647

Categories

Find more on Tables in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!