Opening the book…
MATLAB includes built-in functions that create common matrices quickly. These are very useful when you need to initialize data.
|
Function |
Description |
Example |
|
zeros(n) |
Creates an n-by-n matrix of zeros |
zeros(4) |
|
zeros(m,n) |
Creates an m-by-n matrix of zeros |
zeros(2,4) |
|
ones(n) |
Creates an n-by-n matrix of ones |
ones(4) |
|
ones(m,n) |
Creates an m-by-n matrix of ones |
ones(2,4) |
|
eye(n) |
Creates an n-by-n identity matrix |
eye(3) |
|
eye(m,n) |
Creates an m-by-n identity-style matrix |
eye(2,3) |
Building a few special arrays.
Solution
mat_1 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mat_2 = 0 0 0 0 0 0 0 0 mat_3 = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 mat_4 = 1 1 1 1 1 1 1 1 mat_5 = Diagonal Matrix 1 0 0 0 1 0 0 0 1 mat_6 = Diagonal Matrix 1 0 0 0 1 0
This page titled 4.10: Special 2D Arrays was last modified on Tue, 30 Jun 2026 02:11:57 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.