Effacer les filtres
Effacer les filtres

How to cut out specific segments from a signal?

14 vues (au cours des 30 derniers jours)
Rafael Cordero
Rafael Cordero le 30 Jan 2017
Commenté : Star Strider le 18 Déc 2023
Hi all,
Im going nuts. This should be really easy but i've been stuck on it for days.
Let's say I have a signal (vector) x. There are certain parts of x I want removed/extracted so that I leave behind a shorter version of x, without these parts.
I have two vectors defining these unwanted parts. One that defines that start position (remove_start) and another the end position (remove_end).
So the vectors look like:
x = [x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ...]
remove_start= [11 26 ...] remove_end= [15 31 ...]
I want to get rid of the bold segments in order to get x = [x x x x x x x x x x x x x x], so sticking the non bold bits together. 'x' can take any (real) number.
The problem arises from the fact that when I do something like x(remove_start(i):remove_end(i))=[]; I screw up the timings of remove_start and remove_end. I've tried so many different ways of doing this but none seem to work.
The current way im doing it is:
cut_lag=0;
for i=1:length(remove_start)
x(remove_start(i)-cut_lag(i):remove_end(i)-cut_lag(i))=[];
cut_lag(i+1)=cut_lag(i)+remove_end(i)-remove_start(i);
end
So the idea is to keep track of my cutting out the non-wanted bits has shifted the remaining remove times.
This seems to work for the start of x but it eventually degrades and it ends up cutting out the wrong parts...
Plsss helps, thanks so much!!
R

Réponse acceptée

Star Strider
Star Strider le 30 Jan 2017
If I understand correctly what you want to do, I would begin your loop at the end of the vector and move toward the beginning. That way, you don’t disrupt the other indices.
Something like this:
for i = length(remove_start):-1:1
I didn’t actually run your code, but this is the usual method of removing array elements in a loop without compromising the existing array references.
  4 commentaires
Anusshree
Anusshree le 18 Déc 2023
Thank you star
Star Strider
Star Strider le 18 Déc 2023
@Anusshree — My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by