필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by