Here is a vectorized version:
function [C] = matrix_multiply(A,B)
[m,p] = size(A);
[p,n] = size(B);
C = zeros(m,n);
for k = 1:p
C = C + A(:,k)*B(k,:);
end
end
This avoids the nested for loops and performs the multiplication using matrix operations, making it much faster for large matrices.