To create a new vector with elements of a different vector between a certain range, you can use logical indexing based on the range condition.
Here's an example:
main.m270 chars13 lines
In this example, we create a vector v
with elements from 1 to 9. We then set the range we want to extract elements from, which is from 3 to 7. We create a logical index idx
by checking which elements in v
satisfy the range condition. Finally, we create a new vector new_v
using the idx
index.
The resulting vector new_v
will contain the elements [3 4 5 6 7]
.
gistlibby LogSnag