Remove rows from a table based on the amount of rows in another table
Show older comments
I have two tables, Table1 and Table2 and I'm using them to create a master table called Final.
Table2 is considerably larger than Table1 and I dont need the extra data it provides in those rows. I can get this to work by just looking at the amount of rows and manually entering this value as below:
% Count rows in Table1
rowsd=size(Table1, 1);
% Remove extra rows in Table2
Table2([35400:end], :)=[];
This will remove the rows I dont need and all is good and I can then write my Final table. However, Table1 size will be different each time I use this script I'm writing due to differing input files. I want it to count the number of rows and then use that answer to automate this process.
I've tried the following but just get an error. Can anybody help please? Thank you
% Count rows in Table1
rowsd=size(Table1, 1);
% Remove extra rows in Table2
Table2([rowsd:end], :)=[];
5 Comments
used random table data, but did not find any error
Age = [38;43;38];
Height = [71;69;64];
Weight = [176;163;131];
Table1 = table(Age,Height,Weight); % table 1
rowsd=size(Table1,1);
Height1 = [71;69;64;67;64];
Height2 = [71;69;64;67;64];
Height3 = [71;69;64;67;64];
Height4 = [71;69;64;67;64];
Height5 = [71;69;64;67;64];
Table2=table(Height1,Height2,Height3,Height4,Height5) % table 2
rowsd2=size(Table2,1);
Table2([rowsd:end], :)=[]
Chris Ainsworth
on 28 Feb 2022
Edited: Chris Ainsworth
on 28 Feb 2022
Chris Ainsworth
on 28 Feb 2022
Arif Hoq
on 28 Feb 2022
can you please attch your data ?
Chris Ainsworth
on 28 Feb 2022
Answers (0)
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!