MATLAB: Sum all successive values in matrix row

summation of vectors

I have a vector A which represents 10 machines defect rate. Matrix B shows a process plan in each row in which the elements show process time of one part on corresponding machine for example; row 1 col 4 shows that this part takes 9 minutes to process on machine 4.I want to multiply each row of B with A such that every non zero element of B is multiplies by the sum of corresponding non zero elements of A. for example;
A=[0.1, 0.2, 0.2, 0.4, 0.2, 0.3, 0.1, 0.1, 0.1, 0.2]
B=[0 0 0 9 0 0 10 0 8 8;
8 0 0 0 7 9 0 0 0 10]
C=[0 0 0 (9+9*(0.4+0.1+0.1+0.2)) 0 0 (10+10*(0.1+0.1+0.2) 0 (8+8*(0.1+0.2)) 8+8*0.2;
(8+8*(0.1+0.2+0.3+0.2) 0 0 0 (7+7*(0.2+0.3+0.2) (9+9*(0.3+0.2)) 0 0 0 (10+10*(0.2))]
I tried cumsum and move sum but they are not giving the right answer.

Best Answer

map=(B~=0);
C=cumsum(map.*A,2,'reverse').*B+B