Delete data in one table, based upon another table

24 ビュー (過去 30 日間)
Cameron Kirk
Cameron Kirk 2021 年 1 月 18 日
コメント済み: Cameron Kirk 2021 年 1 月 18 日
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

採用された回答

dpb
dpb 2021 年 1 月 18 日
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.
  1 件のコメント
Cameron Kirk
Cameron Kirk 2021 年 1 月 18 日
That's solved my problem completely! Thanks so much
Cam

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by