How can I sort through a set of tables and remove the duplicates?

2 次查看(过去 30 天)
I am writing code that will output thousands of tables of numbers. The tables will be of varying size (all 3 columns, though, if that helps). How do I go about sorting through these and discarding duplicates?
  1 个评论
Walter Roberson
Walter Roberson 2021-5-15
Are these numeric matrices? Are they table() objects?
Are you looking for matrices that are identical? Are you looking for entries that are identical?

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2021-5-15
isequal() can be used to test whether two table() have the same content and same variable names.
For efficiency, you can group tables according to whether they have the same size(), and then only compare the tables that are the same size.
Put all the tables inside a cell array to make it easier to process them.

Image Analyst
Image Analyst 2021-5-15
Can't be sure since you (unfortunately) forgot to attach your table in a .mat file with the paperclip icon, but I bet it will involve the isequal() function. Attach your table if you need more help. Now, let's say that you discovered your 500th table was exactly identical to the 137th table. Which one do you want to delete? Do the tables all have different names?
if isequal(table500, table137)
clear('table500'); % Or whichever one you want to delete from memory.
end
How are your thousands of tables stored? In a cell array?
itemsToDelete = false(1, length(ca));
for k = 1 : length(ca)
t1 = ca{k}; % Extract the kth table from the cell array.
for k2 = k + 1 : length(ca)
t2 = ca{k2} % Extract the k2th table from the cell array.
if isequal(t1, t2)
% Tables are identical. Mark the later one for deletion.
itemsToDelete(k2) = true;
end
end
end
ca(itemsToDelete) = []; % Remove those items.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by