
Matrix of ones in Octave
In this lesson I'll explain how to make an all-ones matrix in Octave.
I'll give you a practical example.
Create a 3x3 square matrix of ones. Type ones(3,3)
>> ones(3,3)
ans =
1 1 1
1 1 1
1 1 1
Now, create a 3x4 matrix of ones. Type ones(3,4)
>> ones(3,4)
ans =
1 1 1 1
1 1 1 1
1 1 1 1
The first parameter of the ones() function is the number of rows while the second parameter is the number of columns.
This way you can create matrices of any size.