I have an 1xN
array with data, from which I want to cut out the relevant parts.
Basically I have two arrays - beginIndex
and endIndex
- that indicate which parts of data I need to extract.
Example:
data = 1:10;
beginIndex = [1 5 9];
endIndex = [3 6 10];
The desired result would be
partitionedData = [1 2 3 5 6 9 10] %Indices: 1-3, 5-6, 9-10
I already tried
partitionedData = data(beginIndex:endIndex)
The latter gives me the equivalent to
partitionedData = data(beginIndex(1):endIndex(1)) %[1 2 3]
Also I tried accumarray, but the aggregation function must return scalar values. I would really appreciate some help here.
Thank you
Like so: