There are a few ways to add elements to an existing array in Matlab:
Appending an element using the square brackets notation:
22 chars2 lines
This appends new_element
to the end of array A
.
Inserting an element at a specific index using Matlab's index notation:
47 chars2 lines
This inserts new_element
at index index
in array A
.
Concatenating two arrays using square brackets:
12 chars2 lines
This concatenates arrays A
and B
and saves the result in A
.
Here's an example that shows these methods in action:
217 chars15 lines
gistlibby LogSnag