Can someone please explain this code for me?

1 view (last 30 days)
for i=1:ni
for j=1:nj
for k=1:nj
cc(i,j) = cc(i,j)+aa(i,k)*bb(k,j);
end
end
end

Accepted Answer

Ameer Hamza
Ameer Hamza on 26 Oct 2020
It is code for matrix multiplication of two matrices aa (dimensions ni*nj) and bb (dimensions nj*nj). Read here: https://en.wikipedia.org/wiki/Matrix_multiplication. Equivalent MATLAB command is
cc = aa*bb
  3 Comments
Ameer Hamza
Ameer Hamza on 26 Oct 2020
This portion
for k=1:nj
cc(i,j) = cc(i,j)+aa(i,k)*bb(k,j);
end
shows that i-th row if aa is multiplied with j-th column of bb. That is how matrix multiplication is defined.

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!