MATLAB Function Reference Previous page   Next Page
ones

Create an array of all ones

Syntax

Description

Y = ones(n) returns an n-by-n matrix of 1s. An error message appears if n is not a scalar.

Y = ones(m,n) or Y = ones([m n]) returns an m-by-n matrix of ones.

Y = ones(d1,d2,d3...) or Y = ones([d1 d2 d3...]) returns an array of 1s with dimensions d1-by-d2-by-d3-by-....

Y = ones(size(A)) returns an array of 1s that is the same size as A.

ones(m, n,...,classname) or ones([m,n,...],classname) is an m-by-n-by-... array of ones of data type classname. classname is a string specifying the data type of the output. classname can have the following values: 'double', 'single', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', or 'uint64'.

Example

See Also

eye, zeros


Previous page  odextend open Next page

© 1994-2005 The MathWorks, Inc.