MATLAB: Eliminating duplicate columns in a table when appending

table

Hi,
I am importing data using readtable function. but when i append data using:
mytable=[mytable mytable2];
I receive an error: Duplicate variable name: 'ID' because every file contains the ID of the firm. I need the column ID only once. so how can i skip the ID column in mytable2 when i want to append?

Best Answer

Use the join command. Here's a simple example.
% Set up some sample data
id = [1 2 3]';
firstName = {'Walter','Image','Star'}';
lastName = {'Roberson','Analyst','Strider'}';
tableFirst = table(id,firstName);
tableLast = table(id,lastName);
% Join the tables
tableFirstAndLast = join(tableFirst,tableLast)
FYI, there are many input options that govern how the variables in the two tables are retained when there are duplicates, so I suggest carefully reading the documentation (linked above) if this example doesn't do exactly what you want in your case.
You might also need a different function from that family, e.g. innerjoin.