Opening the book…
You can change one element of a matrix by assigning a new value to that row and column location.
Changing one element.
Solution
This changes the value in row 2, column 2 from 20 to 100.
mat2 =
2 10 5
6 100 17
13 2 0
Changing an Entire Row or Column
You can also replace an entire row or column. The replacement must have the correct number of values.
mat2(1,:) = 200:202 % replace the entire first row
Since the first row has three entries, the replacement row must also have three entries: 200, 201, and 202.
Watch the dimensions: If you replace an entire row with a new row, the new row must have the same number of columns. If you replace an entire column, the new column must have the same number of rows.
Extending a Matrix
MATLAB also allows you to extend a matrix by adding a new row or column. For example, we can add a fourth row to a 3-by-3 matrix.
Solution
This creates a new fourth row. If you skip rows or columns while extending an array, MATLAB fills the missing entries with zeros.
mat2 = 2 10 5 6 20 17 13 2 0 9 18 27
This page titled 4.5: Modifying and Extending a Matrix was last modified on Tue, 30 Jun 2026 02:11:56 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.
The book could not be loaded just now.