ones

Returns a matrix of ones.

Syntax

M = ones() returns 1.

M = ones(n) returns an n x n matrix of ones.

M = ones(m, n) returns an m x n matrix of ones.

M = ones(d1, d2, ... dN) returns an N dimensional matrix of ones.

M = ones([d1, d2, ... dN]) returns an N dimensional matrix of ones.

Inputs

m, n, d1, d2, dN, and so on.
The dimension inputs.
Type: integer
Dimension: scalar
A
Type: double | integer
Dimension: matrix

Outputs

M
A matrix of ones.

Examples

Create a 2 x 3 matrix of ones:

M = ones([2,3]);
M = [Matrix] 2 x 3
1  1  1
1  1  1

Create a 2 x 2 x 2 matrix of ones:

M = ones(2,2,2)
M = 
slice(:, :, 1) = 
[Matrix] 2 x 2
1  1
1  1
slice(:, :, 2) = 
[Matrix] 2 x 2
1  1
1  1

Comments

ones(size(A)) is a convenient way to create a matrix of ones with the same dimensions as another matrix.