Here is an example code snippet that creates two 3 by 3 matrices, A
and B
, and then uses a for loop to matrix multiply them together to form matrix C
.
main.m320 chars19 lines
The output of this code will be the following 3 by 3 matrix:
main.m57 chars4 lines
Note that Matlab also provides a built-in function for matrix multiplication, A*B
, which would produce the same result as the for loop above. However, the for loop approach may be useful in cases where you need more control over the ordering of the multiplication or want to customize the multiplication algorithm beyond what is provided by the built-in function.
gistlibby LogSnag