How to set the boundaries?

조회 수: 6 (최근 30일)
Ra Ga
Ra Ga 2018년 3월 18일
댓글: Ra Ga 2018년 3월 18일
Hello,
Please help me :)
I have a row with 0 and 1 (they are used for classification) and its indexes. I need to get just the boundaries for the interval of 0 or 1. How I can do it?
For example this is what I have:
targets=[0 0 0 1 1 1 0 0 1 1 0 0 0]
index= [0 1 2 3 4 5 6 7 8 9 10 11 12]
This is what I want to get:
targ= [0 1 0 1 0]
boundindex=[0 3 6 8 12]
Thanks!

채택된 답변

Image Analyst
Image Analyst 2018년 3월 18일
Try this:
boundindex = [0, find(abs(diff(targets)))]
The only difference is that my array gives 10 as the final value, because 10 is where the final group of 0's starts. Not sure how you got 12. Why do you want 12 and how did you arrive at that value?
Not sure what the point of targ is or why it's needed so I didn't compute it.
  댓글 수: 4
Ra Ga
Ra Ga 2018년 3월 18일
편집: Image Analyst 2018년 3월 18일
I have this:
targets=[0 0 0 1 1 1 0 0 1 1 0 0 0] % describe peaks
index= [0 15 20 35 45 50 60 75 80 99 101 111 120] % index of the peak
I have the row of peaks (PPG signal). 0 - one class, 1 - another class.
What I want to get just bound of the classes, not for each peak. Lets say that first three peaks belong to 0 class and other three to 1 class. So, I want to remove middle values.
This is what I want to get:
targ= [0 1 0 1 0]
index= [0 35 60 80 101]
Image Analyst
Image Analyst 2018년 3월 18일
Try this:
targets=[0 0 0 1 1 1 0 0 1 1 0 0 0] % describe peaks
index= [0 15 20 35 45 50 60 75 80 99 101 111 120] % index of the peak
startingIndexes = [0, find(abs(diff(targets)))]
boundindex = index(startingIndexes+1)
targ = targets(startingIndexes+1)
Shows in command window:
boundindex =
0 35 60 80 101
targ =
0 1 0 1 0
just as you requested.
Also read this how to format your code so I don't have to keep fixing your code formatting.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ra Ga
Ra Ga 2018년 3월 18일
There were some mistakes in my second answer. I need some help to the last question.
  댓글 수: 2
Image Analyst
Image Analyst 2018년 3월 18일
I don't know what to do. What is your "second answer"?
Why is the code I gave in my last comment not what you want? It gave what you said you wanted.
Ra Ga
Ra Ga 2018년 3월 18일
I see your answer at the moment. Previous it looks different. Thank you. It helped me!

댓글을 달려면 로그인하십시오.

카테고리

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