如果你想比较两个数据集之间的给定文件相关联的最大值,可以放弃不用担心在这种情况下的标签。我将使用两个样本数据集从你的问题的例子在这里(假设这些都是像your last question数据tables):
T1 = table([1; 1; 1; 2; 2; 3; 3], ...
{'xxx'; 'xxx'; 'xxx'; 'yyy'; 'yyy'; 'zzz'; 'zzz'}, ...
[6; 2; 3; 1; 4; 6; 7], ...
'VariableNames', {'Label', 'Filename', 'A'});
T2 = table({'yyy'; 'yyy'; 'aaa'; 'aaa'; 'aaa'; 'aaa'; 'zzz'; 'zzz'}, ...
[1; 4; 2; 4; 6; 10; 6; 7], ...
'VariableNames', {'Filename', 'A'});
首先,你可以使用intersect
获得两个表共用的文件列表。然后使用ismember
找到了共同文件的索引中各设置成使用累积值,并与accumarray
找到最大:
T3 = table(commonFiles, max1, max2);
T3 =
commonFiles max1 max2
___________ ____ ____
'yyy' 4 4
'zzz' 7 7
:
commonFiles = intersect(T1.Filename, T2.Filename);
[index, accumIndex] = ismember(T1.Filename, commonFiles);
max1 = accumarray(accumIndex(index), T1.A(index), [], @max); % Max values for set 1
[index, accumIndex] = ismember(T2.Filename, commonFiles);
max2 = accumarray(accumIndex(index), T2.A(index), [], @max); % Max values for set 2
现在我们可以用表格可视化数据在这个例子中,两组中的每个文件的最大值是相同的。如果你想只专注于为不同的人,你可以这样做:
index = (max1 ~= max2); % Index of differing maxima
T3 = table(commonFiles(index), max1(index), max2(index));
对不起,我太忙了审查我的答案,但我认为@gnovice回答希望你所需要的。 – Masoud