MATLAB: Synchronizing Matrix size of multiple matrix such as A=300 x 3, B= 305 x 3 C= 290 x 3and so on. Based on the rows having same dates.

matrix size synch

The 1st column of all matrix represents year-day(i.e 31st Jan 12 noon = 31.5, 1st feb 14:00 Hrs = 32.56 (appx.) 2nd column represents year 3rd column represents the variable
I need to verify the 1st two columns that is year-day and year for all the matrix and remove all those rows in which 1st two column doesn't match. and retain the matrix with 3 columns. of new size where all matrices have same dimensions.

Best Answer

You simply have to use intersect with the 'rows' option repeatedly on your matrices. E.g.:
A = [30 2014 5;
31 2014 6;
35 2014 7;
37 2014 8;]
B = [31 2014 105;
35 2014 106;
37 2014 107;
36 2014 108;]
C = [30 2014 205;
31 2014 206;
34 2014 207;
36 2014 208;
37 2014 209]
etc.
First, since individual matrices are harder to work with, let's put them all in a container (As a rule, don't start numbering or iterating matrix names):
allmatrices = {A, B, C}; %put them all in a cell array
Then you simply loop over the cell array, computing the intersection of the first matrix with the current one, trim all matrices up to the current one.
for matrixiter = 2:numel(allmatrices)
[~, ifirst, isecond] = intersect(allmatrices{1}(:, [1 2]), allmatrices{matrixiter}(:, [1 2]), 'rows'); %intersection taking into account 1st and 2nd column only
for trimiter = 1:matrixiter - 1
allmatrices{trimiter} = allmatrices{trimiter}(ifirst, :); %trim all matrices before the current one.
end
allmatrices{matrixiter} = allmatrices{matrixiter}(isecond, :); %trim current matrix
end
To view the result:
celldisp(allmatrices)
Related Question