In MATLAB, you can add a column to a matrix by using the :
operator to select all rows and concatenating the new column to the right of the selected matrix using the square bracket notation.
Here's an example:
main.m174 chars9 lines
This will create a new matrix newMatrix
which is the original matrix A
with a new column added to the right.
You can add more than one column by simply concatenating additional columns using commas:
main.m167 chars7 lines
This will create a new matrix newMatrix
with the original matrix A
and three new columns added to the right.
gistlibby LogSnag