MATLAB LanguageInitializing Matrices or arrays


Introduction

Matlab has three important functions to create matrices and set their elements to zeroes, ones, or the identity matrix. (The identity matrix has ones on the main diagonal and zeroes elsewhere.)

Syntax

  • Z = zeros(sz,datatype,arraytype)
  • X = ones(sz,datatype)
  • I = eye(sz,datatype)

Parameters

ParameterDetails
szn (for an n x n matrix)
szn, m (for an n x m matrix)
szm,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

These functions will create a matrix of doubles, by default.