Filtering a large vector by two separate vectors with ranges
1 view (last 30 days)
Show older comments
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]
0 Comments
Accepted Answer
Dyuman Joshi
on 6 Nov 2023
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{:}]
0 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB 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!