MATLAB: Adding neighboring numbers in a cell to another cell

MATLAB

When I encounter a -10 in CA, I want to add the two immediate neighboring numbers from CB to it. If the -10 is on an edge/end, ignore it.
% My input would be
CA = {[5 -10 2],[6 6 -10],[0 9 -10 8 -10 3]};
CB = {[4 17 2],[6 6 10],[9 3 4 9 7 6]};
% My output would be
CA = {[5 -4 2],[6 6 -10],[0 9 2 8 5 3]};
% For example: the first -10 encountered (between the 5 and 2 in CA)
% would get 6 added to it (from the 4 and 2 in CB)

Best Answer

CA = {[5,-10,2],[6,6,-10],[0,9,-10,8,-10,3]};
CB = {[4,17,2],[6,6,10],[9,3,4,9,7,6]};
for k = 1:numel(CA)
idx = 1+find(-10==CA{k}(2:end-1));
CA{k}(idx) = CA{k}(idx)+CB{k}(idx-1)+CB{k}(idx+1);
end
Giving:
>> CA{:}
ans =
5 -4 2
ans =
6 6 -10
ans =
0 9 2 8 5 3