OKPEDIA MATLAB EN MATRICE

How to create an array with all elements equal to one in Matlab and Octave

To create an array with elements equal to one in Matlab and Octave use the function ones()

ones(a,b)

The first parameter is the number of rows in the matrix.

The second parameter is the number of columns in the matrix.

Examples

Example 1

Create a 3x2 matrix with three rows and two columns

>> ones(3,2)
ans =
1 1
1 1
1 1

The result is a 3x2 matrix with all elements equal to 1.

Example 2

Create a 2x3 matrix with two rows and three columns

>> ones(2,3)
ans =
1 1 1
1 1 1

The result is a 2x3 matrix with all elements equal to 1

https://how.okpedia.org/en/matlab/how-to-create-an-array-with-all-elements-equal-to-one-in-matlab-and-octave


Report an error or share a suggestion to enhance this page


Matrix in Matlab/Octave


FacebookTwitterLinkedinLinkedin