Vectorization problem for grouping entries in an array

조회 수: 1 (최근 30일)
L'O.G.
L'O.G. . 2023년 4월 17일
댓글: L'O.G. . 2023년 4월 17일
The data below are grouped into three different subgroups based on the value of B(:,3). If, however, B(:,2) <= 1, how do I indicate that all of the entries in that subgroup share a common ID? For example, say I have the following:
B = [
1 1 1 0.1 0.2
2 0 1 0.3 0.1
3 1 1 0.1 0.2
4 2 2 0.6 0.1
5 3 2 0.3 0.7
6 1 3 0.1 0.5
7 0 3 0.5 0.1
8 1 3 0.9 0.2
]
I would like to return
C = [1 0 1];
where the first 1 indicates that the three entries (subgroup 1) with B(:,3) = 1 correspond to type 1, the next subgroup corresponds to type 0, and the third subgroup corresponds to type 0. Is there a robust way of doing this?
  댓글 수: 6
L'O.G.
L'O.G. 2023년 4월 17일
"the third subgroup corresponds to type 1"
>> This is what I meant. Before I had a badly placed typo. So sorry about that!
"And when assigning the type, you give the criteria "B(:,2) > 1" so does that mean ALL col 2 values must be like that, and if so, all rows of that subgroup are that type? "
>> This is correct. All rows of a subgroup will be of the same type.
Does that help? I really hope so.

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

답변 (1개)

Matt J
Matt J 2023년 4월 17일
findgroups(B(:,2)<=1, B(:,3))
  댓글 수: 1
L'O.G.
L'O.G. 2023년 4월 17일
That returns [2 2 2 1 1 3 3 3]' rather than the array C = [1 0 1]

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

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by