MATLAB: How to find matching rows between two matrices and and retrieve a value to be applied to the matched row

additionintersectMATLAB

I'm trying to take matrix (A) & search matrix (B) for matching rows (matching columns 1-5) and retrieve the value from (B) column 6 to be added to matrix (A) column 6.
A={1 1 1 1 1 2; 1 1 1 1 2 3; 1 1 1 1 3 1; 1 1 1 1 4 2; 1 1 1 1 5 8;
1 1 1 1 6 3; 1 1 1 1 7 1; 1 1 1 1 8 0; 1 1 1 1 9 9; 1 1 1 2 0 2};
B={1 1 1 1 2 1; 1 1 1 1 4 1; 1 1 1 1 6 2; 1 1 1 2 0 3; 1 1 1 1 9 3;
1 1 1 1 1 0; 1 1 1 1 3 0; 1 1 1 1 5 0; 1 1 1 1 7 4; 1 1 1 1 8 8};
% Find A's match within B's matrix
[~,~,ib] = intersect(A(:, 1:5), B(:, 1:5), 'rows');
% Get Adjustment (Column 6) values from B
adjustment = B(ib, 6);
% Apply Adjustments to B
for z = 1:length(RxPDW)
A(z,6) = sum(A(z,6),adjustment(z,1));
end
I'm trying get a result of
A={1 1 1 1 1 2; 1 1 1 1 2 4; 1 1 1 1 3 1; 1 1 1 1 4 3; 1 1 1 1 5 9; 1 1 1 1 6 5; 1 1 1 1 7 9; 1 1 1 1 8 13; 1 1 1 1 9 12; 1 1 1 2 0 9}

Best Answer

I don't think your desired result is consistent with your input...
>> [A(:,6) B(ib,6)]
ans =
2 0
3 1
1 0
2 1
8 0
3 2
1 4
0 8
9 3
2 3
>>
I get instead
>> A(ia,6)=A(ia,6)+B(ib,6)
A =
1 1 1 1 1 2
1 1 1 1 2 4
1 1 1 1 3 1
1 1 1 1 4 3
1 1 1 1 5 8
1 1 1 1 6 5
1 1 1 1 7 5
1 1 1 1 8 8
1 1 1 1 9 12
1 1 1 2 0 5
>>
which seems consistent if I look at the results from intersect which also seems consistent with the input by eye...