フィルターのクリア

How to cut out specific segments from a signal?

14 ビュー (過去 30 日間)
Rafael Cordero
Rafael Cordero 2017 年 1 月 30 日
コメント済み: Star Strider 2023 年 12 月 18 日
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

採用された回答

Star Strider
Star Strider 2017 年 1 月 30 日
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 件のコメント
Anusshree
Anusshree 2023 年 12 月 18 日
Thank you star
Star Strider
Star Strider 2023 年 12 月 18 日
@Anusshree — My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by