MATLAB Language Initializing Matrices or arrays

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any MATLAB Language Question?