Detecting samples greater than a threshold and grouping.

조회 수: 3(최근 30일)
Anum Ahmed Pirkani
Anum Ahmed Pirkani 2020년 6월 29일
댓글: Anum Ahmed Pirkani 2020년 6월 29일
Hi all,
Lets say we have a vector: A = [1 2 3 5 2 3 5 2 5 3 10 8 9 11 14 1 4 3 3 4 5 3 2 3 4 5 6 4 2 2 3 4 5 6 6 2 2 3 4 11 23 12 56 23 12 34 12 1 3 4 1 2 3 4 5 ];
In the vector, I have applied a threshold of A>5 for detection of any samples greater than 5. So I detect all the bold samples.
However, as a second step, I want to group these samples. As in, first bold set goes to group 1 and second bold set goes to group 2 (All the consecutive samples goes to same group). How can I do it in Matlab in a way that their original indices in vector A are preserved?
Kind Regards
Anum
  댓글 수: 2
Anum Ahmed Pirkani
Anum Ahmed Pirkani 2020년 6월 29일
It can be something like this
Group1val = [10 8 9 11 14]; %group 1 values greater than threshold
Group1ind = [11 12 13 14 15]; %group 1 indices with values greater than threshold
Group2val = [11 23 12 56 23 12 34 12]; %group 2 values greater than threshold
Group2ind = [40 41 42 43 44 45 46 47]; %group 2 indices with values greater than threshold
Indices can be obtained using the find command i.e.
Indices = find(A>5);
But as a next step, I want to seperate them into (in this case) two groups. This is decided if there are 5 values less than the threshold between the groups (in this case there are 24 values less than the threshold between these two groups).

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

채택된 답변

Image Analyst
Image Analyst 2020년 6월 29일
What you want is bwlabel(), in the Image Processing Toolbox:
A = [1 2 3 5 2 3 5 2 5 3 10 8 9 11 14 1 4 3 3 4 5 3 2 3 4 5 6 4 2 2 3 4 5 6 6 2 2 3 4 11 23 12 56 23 12 34 12 1 3 4 1 2 3 4 5 ];
[groups, numGroups] = bwlabel(A > 5)
groups =
Columns 1 through 27
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 2
Columns 28 through 54
0 0 0 0 0 0 3 3 0 0 0 0 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0
Column 55
0
numGroups =
4
  댓글 수: 1
Anum Ahmed Pirkani
Anum Ahmed Pirkani 2020년 6월 29일
Oh brialliant. Thanks a lot... This is exactly what I needed.

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by