Filtering a large vector by two separate vectors with ranges

I have a large dataset with about 140,000 rows, I am trying to filter out the rows into certain ranges, which I have stored in two separate column vectors: 1 column for the start indeces, and one for the end indeces. I want to form a vector of this form: [start(1):end(1) start(2):end(2) .... ]. Since each range is not equal in value, I am having trouble using a loop to join the vectors together. Any help is appreciated, Thank you.
Example:
Start = [1; 10; 20];
End = [5; 17; 25];
Desired Result: [1 2 3 4 5 10 11 12 ... 17 20 21 ... 25]

 Accepted Answer

Start = [1; 10; 20];
End = [5; 17; 25];
n = numel(Start);
C = cell(1,n);
for k=1:n
C{1,k} = Start(k):End(k);
end
C = [C{:}]
C = 1×19
1 2 3 4 5 10 11 12 13 14 15 16 17 20 21 22 23 24 25

More Answers (0)

Categories

Products

Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!