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
Related Topics
MATLAB diagonal matrixdiag() command or function gives diagonal elements or creates a diagonal matrix, after reading this…
MATLAB matrix inverseinv( ) command or function gives the inverse of a matrix, after reading this MATLAB…
MATLAB zeroszeros() command creates an array of all zeros, after reading this MATLAB zeros topic, you…
MATLAB titletitle() command puts the title on the plot, after reading this MATLAB title topic, you will…
MATLAB ylabelThe ylabel command put the label on the y-axis of the plot, after reading this…