A = [-1,-1,0,0,4,1,3,0,1,1;
-1,1,1,0,2,1,1,0,0,1;
0,0,1,0,1,0,1,0,2,0];
B = [3,5;
2,6;
1,7];
Expected Output Cell Array (one column):
C = [4,4,4,4,4,4,4,4,4,4; %// sum of elements 3,4,5 is 4
5,5,5,5,5,5,5,5,5,5; %// sum of elements 2,3,4,5,6 is 5
3,3,3,3,3,3,3,3,3,3]; %// sum of elements 1,2,3,4,5,6,7 is 3
Matrix B includes which columns should be used to execute the condition on Matrix A. For example, first row of B is 3 and 5; so elements between 3rd and 5th column of matrix A should be used to execute the condition. Second row of B is 2 and 6; so elements between 2nd 6th column should be used to execute the condition. And so on...
The condition: sum specified elements and then replace all elements of the related row with the calculated sum. For example, A includes 0,0,4 (sum is 0+0+4=4), so write 4 to all elements of first row of matrix C.
Without for loop, only with matrix operations, how can I do this task?