To only keep selected indexes of an array in MATLAB, you can use indexing to create a subset of the original array.
Here's an example:
main.m226 chars9 lines
In this example, indices_to_keep
contains the indices that we want to keep from the original array A
. We then create a new variable subset
that only contains the elements of A
with those indices.
The resulting subset
array would be:
main.m29 chars4 lines
Note that this method can also be used for multidimensional arrays by specifying a subset of indices for each dimension.
gistlibby LogSnag