ones
Array of all ones.
Syntax
Section titled “Syntax”B = onesB = ones(n)B = ones(m, n)B = ones(d1, d2, d3, ...)B = ones([d1 d2 …])B = ones(…, classname)Description
Section titled “Description”Creates an array of all ones with the given dimensions. Same shape conventions as zeros, including the optional trailing class-name string for element type selection.
Examples
Section titled “Examples”ones(3) % 3×3 onesones(1, 5) % row vector of five 1sones(4, 'single') % 4×4 single-precision