MATLAB: vectorized array creation from a list of start/end indices

Posted by merv on Stack Overflow See other posts from Stack Overflow or by merv
Published on 2010-05-11T00:06:06Z Indexed on 2010/05/11 0:14 UTC
Read the original article Hit count: 484

Filed under:
|

I have a two-column matrix M that contains the start/end indices of a bunch of intervals:

startInd   EndInd
1          3
6          10
12         12
15         16

How can I generate a vector of all the interval indices:

v = [1 2 3 6 7 8 9 10 12 15 16];

I'm doing the above using loops, but I'm wondering if there's a more elegant vectorized solution?

v = [];
for i=1:size(M,1)
    v = [v M(i,1):M(i,2)];
end

© Stack Overflow or respective owner

Related posts about matlab

Related posts about vectorization