如果你想比較兩個數據集之間的給定文件相關聯的最大值,可以放棄不用擔心在這種情況下的標籤。我將使用兩個樣本數據集從你的問題的例子在這裏(假設這些都是像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