how to create series of indices from vectors of numbers
Show older comments
Sorry for the obscure title, I think if i show an example it will be easy to understand. I have a vector of numbers: myvec = [ 1 45 70 ]; and I want to somehow generate a set of indices like this:
output = [1 2 3 4 5 6 7 8 9 10 11 45 46 47 48 49 50 51 52 53 54 55 70 71 72 73 74 75 76 77 78 79 80 ]
if i wrote a for loop, it would look like this:
for( i = 1:length(myvec) ) output = [output myvec(i):myvec(i)+10]; end
is there a simple, vectorized way to do this in matlab? for loops are terribly slow, and I want my code to be as fast as possible. thanks!
Liz
Accepted Answer
More Answers (0)
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!