To add the first row to a matrix in Matlab, you can use the following code:
main.m222 chars9 lines
In this example, I created a row vector called newRow
with the values [1 2 3]
. Then, I created an original matrix called oldMatrix
with the values:
main.m34 chars3 lines
To add the newRow
vector as the first row of the oldMatrix
, I used the vertcat
function (represented by the square bracket notation [ ]
) to concatenate newRow
above the oldMatrix
, resulting in:
main.m51 chars4 lines
This new matrix is stored in the newMatrix
variable.
gistlibby LogSnag