我们有以下的矩阵result
:Matlab的:分组和最小化矩阵的唯一列元素的索引
result =
Columns 1 through 13
3 1 1 1 1 1 6 2 3 6 2 1 6
4 3 3 5 7 5 10 10 4 10 6 9 8
6 4 4 7 9 7 0 0 0 0 0 0 0
10 5 5 8 0 0 0 0 0 0 0 0 0
Columns 14 through 25
2 10 3 10 3 8 8 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
其列独特元素的索引规模(不为零):
Indexes of result:
Columns 1 through 13
4 4 4 4 3 3 2 2 2 2 2 2 2
Columns 14 through 25
2 1 1 1 1 1 1
我想执行以下场景: 从第一列开始,我们想要限制每个非唯一值在矩阵中仅出现一次。因为我们看到COL4拥有最独特的元素
result =
Columns 1 through 13
3 1 1 1 1 1 0 2 0 0 2 1 0
4 0 0 5 7 5 0 0 0 0 0 9 8
6 0 0 7 9 7 0 0 0 0 0 0 0
10 5 5 8 0 0 0 0 0 0 0 0 0
Columns 14 through 25
2 0 0 0 0 8 8 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Indexes of result (without zeros):
Columns 1 through 13
4 2 2 4 3 3 0 1 0 0 1 2 1
Columns 14 through 25
2 0 0 0 0 1 1
现在,让我们考虑它的价值,继续第二重排,结果是: 因此,与COL1为出发点矩阵的其余部分应被重新排列:
result =
Columns 1 through 13
3 0 0 1 0 0 0 2 0 0 2 0 0
4 0 0 5 0 0 0 0 0 0 0 9 0
6 0 0 7 9 0 0 0 0 0 0 0 0
10 0 0 8 0 0 0 0 0 0 0 0 0
Columns 14 through 25
2 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Indexes of result (without zeros):
Columns 1 through 13
4 0 0 4 1 0 0 1 0 0 1 1 0
Columns 14 through 25
1 0 0 0 0 1 1
否则,按照需要多次,在例如两次为COL5和col8我们达到预期的结果:
result =
Columns 1 through 13
3 0 0 1 0 0 0 2 0 0 0 0 0
4 0 0 5 0 0 0 0 0 0 0 0 0
6 0 0 7 9 0 0 0 0 0 0 0 0
10 0 0 8 0 0 0 0 0 0 0 0 0
Columns 14 through 25
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Indexes of result (without zeros):
Columns 1 through 13
4 0 0 4 1 0 0 1 0 0 0 0 0
Columns 14 through 25
0 0 0 0 0 0 0
哪是执行此操作的最有效方法? 我可以看看你的建议吗?
预先感谢您。
你的问题是什么? –
@EitanT我的问题是找到一种方法来执行这个特定的分组 - 最小化加上找到最有效的方式来做到这一点。 – professor
你不是自己实现它吗?那么你是如何得到这些结果的? –