create a column vector in matlab

To create a column vector in MATLAB, you can use the colon operator with semicolons to separate the elements. For example:

main.m
% create a column vector of integers from 1 to 5
column_vector = [1; 2; 3; 4; 5];
82 chars
3 lines

You can also use the transpose (') operator to create a column vector from a row vector. For example:

main.m
% create a row vector of integers from 1 to 5
row_vector = [1 2 3 4 5];

% create a column vector from the row vector
column_vector = row_vector';
147 chars
6 lines

Note that the transpose operator can also be written as a period followed by the apostrophe (.').

main.m
% create a column vector using the period-apostrophe operator
column_vector = row_vector.';
92 chars
3 lines

Either method will result in the same column vector:

main.m
column_vector =

     1
     2
     3
     4
     5
52 chars
8 lines

related categories

gistlibby LogSnag