MATLAB ones

This command creates an array of all ones, after reading this MATLAB ones topic, you will know the theory, and examples, and you will understand how to create a matrix with all elements one in MATLAB.


Syntax:

ones(n)
ones(n,m)

  • For ones(n) represents n columns and n rows.
  • For ones(n,m) represents n rows and m columns.

Example: To create 2×2 ones matrix.

ones(2)

Output:

ans =

1 1
1 1

Example: To create 2×3 ones matrix.

ones(2,3)

Output:

ans =

     1     1     1
     1     1     1

Leave a Comment

error: Content is protected !!