MATLAB: How to find common calendar of three matrices

MATLABmatricesmatrixmatrix array

I have three matrices that have common calendar. A part of these matrices is as follows:
A=[2000 1 2 230 240; 2000 1 3 240 250; 2000 1 5 260 270];
B=[2000 1 4 240 260; 2000 1 2 270 300; 2000 1 5 200 210];
C=[2000 1 5 240 260; 2000 1 7 270 300; 2000 1 2 200 210];
I want to extract the common calendar. For example, in the example above, the result is as follows:
D=[2000 1 2 230 240 2000 1 2 270 300 2000 1 2 200 210;
2000 1 5 260 270 2000 1 5 200 210 2000 1 5 240 260];
Thanks,

Best Answer

ABC=[A;B;C];
d=datetime(ABC(:,1:3));
g=findgroups(d);
D=splitapply(@(x) {vertcat(x)},ABC,g);
D=cell2mat(D(cellfun(@(c)size(c,1),D)>1));
D=reshape(D.',max(histc(g,unique(g)))*size(ABC,2),[]).'
The last presumes the number of matching dates is the same in all groups to be able to reshape to a rectangular array; the previous array will be the groups with more than one element in an column-oriented array; that step without cell2mat will leave a cell array with the duplicated dates in separate cells that could have differering numbers but still with at least two elements per cell.