Is it possible to Join two dataset in malab? I imported a MATLAB file into MATLAB as a table and I have another set of data in form of an array in a separate variable .

1 次查看(过去 30 天)
Is it possible to Join two dataset in malab? I imported a MATLAB file into MATLAB as a table and I have another set of data in form of an array in a separate variable. Please How do I merg the data to Have them both in one table? Thanks

回答(1 个)

Voss
Voss 2022-5-6
"How do I merge the data to have them both in one table?"
It depends on how what's in the array corresponds to what's in the table.
If: (1) the table has the same number of variables as the array has columns, and (2) all variables in the table are column vectors, and (3) you want to add the array to the end of the table, and (4) each variable in the table should match with the corresponding column of the array (i.e., they're in the same order), then it's pretty easy to do:
one_table = table([1;2;3],[4;5;6],[7;8;9])
one_table = 3×3 table
Var1 Var2 Var3 ____ ____ ____ 1 4 7 2 5 8 3 6 9
separate_array = 10*magic(3)
separate_array = 3×3
80 10 60 30 50 70 40 90 20
separate_table = array2table(separate_array,'VariableNames',one_table.Properties.VariableNames);
final_table = [one_table; separate_table]
final_table = 6×3 table
Var1 Var2 Var3 ____ ____ ____ 1 4 7 2 5 8 3 6 9 80 10 60 30 50 70 40 90 20
But I had to make 4 assumptions about the situation and your objective. If any of those assumptions are incorrect, then you'll have to do something else. The actual situation may be almost as easy to deal with as this simple case, or it may be much more difficult or impossible to achieve your objective.

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by