Vectorization problem for grouping entries in an array
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2023-4-17
So when you said "the next subgroup corresponds to type 0, and the third subgroup corresponds to type 0", meaning the second and third subgroup are both zero, that was wrong? You really meant "the third subgroup corresponds to type 1"?
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? OR do you check that on a row by row basis so each row will have it's own type and you might have multiple types within a subgroup. For example
B = [
1 1 1 0.1 0.2
2 0 1 0.3 0.1
3 9 1 0.1 0.2];
Would the type be
theType = B(:, 2) > 2
or something else?
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!