MATLAB: Loop for nested matrix multiplication

nested matrix multiplication loop

Hello guys,
My problem is the following.
I have two matrices: a 155*3 matrix and a 465*3 matrix. I have to multiply each 1×3 row (from the 155*3 matrix) with each consecutive 3×3 matrix from the 465*3 matrix.
Now the loop I tried did not work out and I just can't get my thought's around it.
Here's my code:
m = size(A,2);
n = B(D:E);
D = B(1,:);
E = B(1:3,:);
C = zeros(m,n);
for ii = 1:m
for jj = 1:n
C(ii,jj) = sum(A(ii,:).*B(:,jj).');
end
end
Where matrix A is the 155*3 matrix and matrix B is the 465*3 matrix.
Any suggestions how to adjust the loop?
Thanks a million.
Kevin

Best Answer

eg:
A = randi(4,155,3);
B = randi(8,455,3);% your matrices A and B
one variant;
s = size(A);
C = zeros(s);
for j1 = 1:s(1)
C(j1,:) = A(j1,:)*B((j1-1)*s(2)+1:j1*s(2),:);
end
other variant
s = size(A);
C = zeros(s);
for j1 = 1:s(1)
C(j1,:) = B((j1-1)*s(2)+1:j1*s(2),:)*A(j1,:)';
end