I want to replace the for loop with matrix operations. I have a minimal working example of what my code does:
A = [1,2,3,4,5,6,7,8,9,10];
B= [5,2,3,4,5,1,4,7,4,2];
C = zeros(1,10);
n = length(A);
abMatrix = [1,-1,0;1,-2,1;0,-1,1];
for i=2:n-1
C(i) = A(i-1:i+1) * abMatrix * B(i-1:i+1)';
end
This operation works, but I would really like to do the operation for all i = [2, n-1] in one matrix operation. How can I remove the for-loop?
source
share