I'd like to merge two different tables on matlab, how do I do that?
15 views (last 30 days)
Show older comments
Hello to anyone reading this,
I have two excel tables which I'd like to merge into one big table / array. Basically, they all have different columns, and different number of rows and lines. The only similar thing is the first column, which is time (in seconds). Some values are similar in both tables, while others are different.
If possible, I'd like to merge the two tables into one big table without losing any data. Example of what I have / want:
Have:
Time1 = ["t1";"t2";"t3"];
value1 = [374; 164; 476];
value2 = [2455;5478;2354];
value3 = [53782;35683;24682];
table1 = table(Time1, value1, value2, value3)
Time2 = ["t1";"t4"];
value4 = [257;31572];
value5 = [247;3578];
table2 = table(Time2, value4, value5)
I'd like to get:
Time3 = ["t1";'t2';'t3';'t4'];
value1 = [374; 164; 476;""];
value2 = [2455;5478;2354;""];
value3 = [53782;35683;24682;""];
value4 = [257;"";"";31572];
value5 = [247;"";"";3578];
table3 = table(Time3, value1, value2, value3, value4, value5)
I'd appreciate any help/advice with that, thanks in advance!
Important: my table contains both numbers and words.
(Small disclaimer: i'm fairly new to matlab so don't know much about it yet)
2 Comments
Accepted Answer
Matt J
on 27 Mar 2023
Time1 = ["t1";"t2";"t3"];
value1 = [374; 164; 476];
value2 = [2455;5478;2354];
value3 = [53782;35683;24682];
table1 = table(Time1, value1, value2, value3,'Var',{'Time','V1','V2','V3'})
Time2 = ["t1";"t4"];
value4 = [257;31572];
value5 = [247;3578];
table2 = table(Time2, value4, value5,'Var',{'Time','V4','V5'})
table3 = outerjoin(table1,table2,'MergeKeys',1)
2 Comments
Walter Roberson
on 27 Mar 2023
The implication of the error message is that Seconds_s_ and Marker each occur in both tables, but in one of the tables they are double and in the other table they are cell .
When you have the same variable in both tables, then in order to join the tables, the variable must be compatible types in the two tables.
More Answers (0)
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!