Initializing Matrices or arrays
Creating a matrix of 0s
Section titled “Creating a matrix of 0s”z1 = zeros(5); % Create a 5-by-5 matrix of zeroesz2 = zeros(2,3); % Create a 2-by-3 matrixCreating a matrix of 1s
Section titled “Creating a matrix of 1s”o1 = ones(5); % Create a 5-by-5 matrix of oneso2 = ones(1,3); % Create a 1-by-3 matrix / vector of size 3Creating an identity matrix
Section titled “Creating an identity matrix”i1 = eye(3); % Create a 3-by-3 identity matrixi2 = eye(5,6); % Create a 5-by-6 identity matrixSyntax
Section titled “Syntax”- Z = zeros(sz,datatype,arraytype)
- X = ones(sz,datatype)
- I = eye(sz,datatype)
Parameters
Section titled “Parameters”|Parameter|Details |---|---|---|---|---|---|---|---|---|--- |sz|n (for an n x n matrix) |sz|n, m (for an n x m matrix) |sz|m,n,…,k (for an m-by-n-by-…-by-k matrix) |datatype|‘double’ (default), ‘single’, ‘int8’, ‘uint8’, ‘int16’, ‘uint16’, ‘int32’, ‘uint32’, ‘int64’, or ‘uint64’ |arraytype|‘distributed’ |arraytype|‘codistributed’ |arraytype|‘gpuArray’
Remarks
Section titled “Remarks”These functions will create a matrix of doubles, by default.