Delete data in one table, based upon another table

22 views (last 30 days)
Hellooo,
So I have two tables in matlab which contain the exact same variables. The only difference is that one table contains more rows (participants) than the other, which is incorrect as these participants need to be removed.
So I'm trying to write a loop condition which takes the participant ID number (listed as a variable in the dataset) from the incorrect dataset, checks if this is listed in the correct dataset. Then if it's not present in the correct dataset, I want matlab to delete the whole row that the incorrect name appears on.
The output I want from this is two idential datasets with the same number of rows
this is the loop I've written so far:
But this code gives me the message: Operator '==' is not supported foroperands of type 'cell'.
Any help would be massively appreciated!
Thanks
Cam
for iFalsename = 1:nFalseNames
FalseNameNow = FalseNames2(iFalseName);
for iTrueName = 1:nTrueNames
TrueNameNow = TrueNames2(iTrueName); % Keep if TrueNameNow exist in FalseData
if eq(TrueNameNow, FalseNameNow)
% Insert code to remove column
end
end
end

Accepted Answer

dpb
dpb on 18 Jan 2021
It would be easier to write working code if we knew the actual format of the variables -- is it really a MATLAB table object or is that just figure of speech for an array of some type?
Either way, you don't need a loop here, simply
tGood2=tBad(contains(tBad.ID,tGood.ID),:);
assumes a table with a variable ID. It extracts the rows from the "Bad" table tBad that have IDs that are those in the "Good" table.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!