【发布时间】:2012-12-02 12:16:18
【问题描述】:
我们有以下矩阵result:
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
我想执行以下场景: 从第一列开始,我们希望限制每个非唯一值在矩阵中仅出现一次。 所以以 col1 为起点,矩阵的其余部分应重新排列为:
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
现在我们看到 col4 有最独特的元素,所以我们考虑它的值继续第二次重新排列,结果是:
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 我的问题是找到一种方法来执行这个特定的分组 - 最小化 plus 以找到最有效的方法。
-
你不是已经自己实现了吗?那你是怎么得到这些结果的?
-
@EitanT 我已经实现了它,而无需将尽可能多的元素与更少的列相关联。结果代表了期望的结果,并且是手工制作的。
标签: matlab size unique minimize