In MATLAB, you can create a vector using square brackets containing comma-separated elements:
main.m29 chars2 lines
Alternatively, you can use the linspace
or logspace
functions to create a vector with equally spaced or logarithmically spaced values, respectively.
To access a particular element of a vector, you can use indexing with round brackets ()
:
main.m29 chars2 lines
To update a particular element of a vector, you simply assign a new value to that element:
main.m18 chars2 lines
You can also update multiple elements in one go using indexing and assignment:
main.m31 chars2 lines
Note that in MATLAB, vectors are actually a special case of arrays, where the array has only one row or column. Therefore, you can use all the same array operations on vectors, such as transposing, concatenating, and reshaping.
gistlibby LogSnag