Joining Tables and deleting columns
Show older comments
Hi everyone,
How can I add two tables into a third table and how can I delete columns in a third table.
I have two tables which only contains 1 column of information. However, the information is required to replace data contained under two headings in another table - SecondVID and FirstVID.
How can I take the column data of the two tables and insert it into the third?
5 Comments
Matt J
on 27 Mar 2023
We'd probably need an example.
This seems like essentiallyt the same question as asked in
You've used the word "join", and there are join methods for tables, but I think that kind of join is overkill. I think all you want to do (if the previous question is any indication) is find values from one variable that are in another variable, and overwrite them. ismember is what I think you need.
x = [1;2;3;4;5];
y = [1;3;5];
x(ismember(x,y)) = NaN
Now do that with variables in your tables, using, like, t1.Var1 and t2.Var2. In your previous question, you asked to overwrite numbers with text, which is not going to work unless you use cell arrays, which, you don't want to do that. I recommend you start with text, in other words, treat 1,2,3 as identifiers, not as numbers.
x = ["1";"2";"3";"4";"5"];
y = ["1";"3";"5"];
x(ismember(x,y)) = "Howdy!"
Jana Sarran
on 28 Mar 2023
Edited: Jana Sarran
on 28 Mar 2023
Peter Perkins
on 4 Apr 2023
I'm pretty sure my previous post exactly answered what you've described:
- Find values from one vector in another vector.
- Replace the values in the other vector with something else.
- The something else is text.
Answers (1)
Swaraj
on 4 Apr 2023
0 votes
Step 1: Joining two tables
You can join two tables in MATLAB using the “join()” function.
Eg. Table3 = join(table1,table2);
Documentation for “join()”:
Step 2: Removing a column from the third table.
You can use “removevars” function.
Documentation for “removevars” function.
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!

