Matrices and Basic Operations
A matrix is just a 2D array of numbers — in MATLAB, you build one the same way you built a vector, just with semicolons separating rows.
Creating a matrix
A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
This is a 3x3 matrix. size(A) tells you its dimensions; A(2,3) gets the entry in row 2, column 3 (MATLAB indexing starts at 1, not 0).
Transpose
A'
The single quote flips rows and columns.
Matrix multiplication vs. element-wise
This trips up almost everyone at first:
A * B % real matrix multiplication (dimensions must agree)
A .* B % element-wise multiplication (same-size matrices, multiplies entry by entry)
The dot before an operator (.*, ./, .^) always means "do this element by element" instead of the real linear-algebra operation.
Why This Matters for Your Exams
Forgetting the dot in .*/./ is the single most common source of a "matrix dimensions must agree" error — if you see that error, check your operators before anything else.
Try it yourself
Real-time practice is a paid add-on
Reading units and the practice quiz are free. Pay once to unlock running real code for LaTeX & MATLAB.

