MATLAB: How to transform a matrix to be similar to another matrix

matrix manipulation

Hi, I'm new with MATLAB and I have a bit of problem regarding matrix transformation.
I have two matrix A & B
and
You can see that the first row of those matrix are years, then the second row are weeks in that year and the last one is the value. I want to transform matrix B based on matrix A, so that I have
It can be seen that the transformed matrix B has similar column number as matrix A. The first two row is the same as matrix A, but the last row is different. It has the same value as the old matrix B and just add 0 in the missing one. I hope this explanation is good enough to describe the problem.

Best Answer

A = [2015,2015,2015,2016,2016,2016,2016,2017,2017,2017;...
32, 36, 42, 14, 25, 32, 36, 3, 12, 18;...
12, 13, 4, 7, 8, 6, 5, 21, 12, 6];
B = [2015,2015,2016,2017;...
32, 42, 25, 3;...
6, 8, 12, 4];
[~,idx] = ismember(B(1:2,:).',A(1:2,:).','rows');
C = A(1:2,:);
C(3,idx) = B(3,:)
Giving:
C =
2015 2015 2015 2016 2016 2016 2016 2017 2017 2017
32 36 42 14 25 32 36 3 12 18
6 0 8 0 12 0 0 4 0 0