Merge tables with duplicates

7 Ansichten (letzte 30 Tage)
Jonas Schmeiss
Jonas Schmeiss am 2 Sep. 2016
Bearbeitet: Jonas Schmeiss am 2 Sep. 2016
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 2 Sep. 2016
This not clear. To illustrate, post two tables,for example: 8x7 and 6x4, then post the expected result
Jonas Schmeiss
Jonas Schmeiss am 2 Sep. 2016
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 =/

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mischa Kim
Mischa Kim am 2 Sep. 2016
Hi Jonas, why not rename the columns of one of the tables, or even both? E.g. CO21 and CO22. See this answer.
  3 Kommentare
Mischa Kim
Mischa Kim am 2 Sep. 2016
Bearbeitet: Mischa Kim am 2 Sep. 2016
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 am 2 Sep. 2016
Bearbeitet: Jonas Schmeiss am 2 Sep. 2016
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.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by