Extract values between successive start stop indexes from a signal

1 view (last 30 days)
Hello everyone,
I have data with defined start and stop indexes. However for further processing i have to extract only the values between those starts stops for computing several variables. The circles below are the starts and the stars are the stops. I need to perform computational operations only between those intervals. So is there a way to extract only the data between those regions?
Really appreciate any help. Thanks a lot.

Accepted Answer

darova
darova on 20 Aug 2019
I think there are tricks with vectorizing but i like simple and clear solution even it's slower
x0 % your data
x = [];
ind = [1 4 7 9 12 15]; % i want data between (1,4) (7,9) (12,15)
for i = 1:2:length(ind)-1
j = ind(i):ind(i+1)
x = [x x0];
end
  2 Comments
Christos Chalitsios
Christos Chalitsios on 20 Aug 2019
Thank you a lot darova for your aswer really nice solution. I have a question though. I forgot to mention that the i have extracted the starts and stops as different vectors. Is there a way to merge them in way that after the first start value will go the fisrt stop value and not the second start? below i paste the code for computing start and stop indexes.
Thanks a lot for your help!!!
for k=1:length(locs)
Ftemp=ftotal;
i=locs(k);
while Ftemp(i)>=find(Ftemp(i)>=300 & Ftemp(i)>0,1)
i=i-1;
while Ftemp(i-1)-Ftemp(i)<0
i=i-1;
end
end
startindex1(k)=i;
end
for k=1:length(locs)-1
Ftemp=ftotal;
i=locs(k);
while Ftemp(i)>=find(Ftemp(i)>=300 & Ftemp(i)>0,1)
i=i+1;
while Ftemp(i+1)-Ftemp(i)<0
i=i+1;
end
end
stopindex1(k)=i;
end
darova
darova on 20 Aug 2019
Of course!
ind = [];
for k = 1:length(locs)
curr_ind = startIndex1(k):stopIndex1(k);
ind = [ind curr_ind];
end

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!