Merge tables with duplicates
7 次查看(过去 30 天)
显示 更早的评论
Hi, I couldn't find an answer to my problem yet so here we go.
There are 2 big tables(1800x505 and a 1800x309 table), lets call them table1 and table2. I want to merge them to 1 big table.
The problem is that in those tables there are Columns with the same name for example "CO2". in the first table with data like {5;2;2;4} and in the second with {4;3;9;1} If I want to plot "CO2" later over a time{1;2;3;4} I want to see both graphs.
so how do I merge those tables to fill "CO2" with botch sets of data? Is it possible?
for testing here is the small sample code:
table1 = {5;2;2;4};
table2 = {4;3;9;1};
table1=table(table1,'VariableNames',{'CO2'});
table2=table(table2,'VariableNames',{'CO2'});
now I want to merge those but not sure how
table=[table1,table2]; or table= join(table1,table2); neither works or gives me the result I want
2 个评论
Azzi Abdelmalek
2016-9-2
This not clear. To illustrate, post two tables,for example: 8x7 and 6x4, then post the expected result
回答(1 个)
Mischa Kim
2016-9-2
Hi Jonas, why not rename the columns of one of the tables, or even both? E.g. CO21 and CO22. See this answer.
3 个评论
Mischa Kim
2016-9-2
编辑:Mischa Kim
2016-9-2
Understood. Again, you can merge the tables and then create the plot with only one command. Does this satisfy your needs?
CO21 = [5;2;2;4];
CO22 = [4;3;9;1];
time = [1;2;3;4];
table1 = table(CO21,'VariableNames',{'CO21'});
table2 = table(CO22,'VariableNames',{'CO22'});,
table3 = table(time,'VariableNames',{'Time'});
table = [table1 table3 table2];
plot(time,table2array(table(:,strmatch('CO2',table.Properties.VariableNames))));
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!