Can someone please explain this code for me?
1 view (last 30 days)
Show older comments
Nicolaas George Edward
on 26 Oct 2020
Commented: Nicolaas George Edward
on 26 Oct 2020
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
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!