Merge tables with duplicates

6 ビュー (過去 30 日間)
Jonas Schmeiss
Jonas Schmeiss 2016 年 9 月 2 日
編集済み: Jonas Schmeiss 2016 年 9 月 2 日
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
Azzi Abdelmalek 2016 年 9 月 2 日
This not clear. To illustrate, post two tables,for example: 8x7 and 6x4, then post the expected result
Jonas Schmeiss
Jonas Schmeiss 2016 年 9 月 2 日
tables must have the same height otherwise I cant plot them.
I just want to use the same function like I have in cells
z{1}=[5;2;2;4];
z{2}=[4;3;9;1];
time=[1;2;3;4];
plot(time,cell2mat(z))
maybe im bad at explaning =/

サインインしてコメントする。

回答 (1 件)

Mischa Kim
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
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))));
Jonas Schmeiss
Jonas Schmeiss 2016 年 9 月 2 日
編集済み: Jonas Schmeiss 2016 年 9 月 2 日
yes probably will do, just need to find a loop now that renames those variable names while i try to put the tables together and a duplicate appears.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by