向量列表,其元素的总和等于循环变量
我想创建一个向量列表,其中列表中每个向量的元素总结到循环变量,而无需考虑元素和重复的顺序。 例如。
k=1, list ={[1]};
k=2, list ={[1,1],[2]};
k=3, list ={[1,1,1],[1,2],[2,1],[3]};
k=4, list ={[1,1,1,1],[1,3],[3,1],[2,2],[2,1,1],[1,2,1],[1,1,2],[4]};
等等。 列表的长度为$ 2^{k-1} $。在MATLAB中有什么简单的策略吗?
I want to create a list of vectors, where the elements of each vector in the list sums up to the loop variable without considering order of elements and repetition into account.
For eg.
k=1, list ={[1]};
k=2, list ={[1,1],[2]};
k=3, list ={[1,1,1],[1,2],[2,1],[3]};
k=4, list ={[1,1,1,1],[1,3],[3,1],[2,2],[2,1,1],[1,2,1],[1,1,2],[4]};
and so on.
The length of the list is $2^{k-1}$. Is there any easy strategy to do this in MATLAB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个简单的递归策略:如果您有一些具有一些
k-1
的整数分区列表,则很容易地使用SUMk
生成分区:给定一些分区,我们可以附加1来创建一个新的分区,或者我们可以增加最后一个条目。There is an easy recursive strategy: If you have a list of the integer partitions with the sum of some
k-1
, it is easy to generate the partitions with sumk
: Given some partition, we can either append an 1 to create a new partition, or we can just increment the last entry., so something like this should work.