I have a main matrix, say
A=magic(5);
and also a vector
v=[1;3;5;2;2];
I want to add up row-wise the elements of A in this way: add first row from the v(1)st element to the end, second row from the v(2)rd element to the end, third row from the v(3)th element to the end, and so on.
I know that I can do this using for-loop. But I want to know if there is a vectorized way to do it.
edit: Let me clarify my question with an example: Assume A and v as above.
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
and
v =
1
3
5
2
2
Now I want a way to get the following results:
answer =
65 % 17+24+1+8+15
37 % 7+14+16
22 % 22
55 % 12+19+21+3
54 % 18+25+2+9