summations of combinations of elements, one from each column of a 2D matrix, in small to large order
2 次查看(过去 30 天)
显示 更早的评论
I have a 2D numerical matrix of size 1000 by 8: [0 a1 a2 a3 a4 ... a999; 0 b1 b2 b3 b4 ... b999; ... ; 0 h1 h2 h3 h4 ... h999]' , where each column is in ascending order, i.e., 0<a1<a2<a3<...<a999, etc. However, I don't know how a1 compares to b1, or c1, etc. For example, b100 could be smaller than a1.
Now, I would like to find the first 1000,000 combinations of 8 elements, each coming from a column, that have the smallest summation values. For each combination, I would like to retain the row and column indices of each element as well.
Can anyone help me with the problem? Thank you very much for your help in advance.
1 个评论
Mathieu NOE
2024-6-10
seems to me that because your 8 columns of data contains sorted values , the first combination of 8 values (each one picked in a separate column) is the first row of the 8 cols.
if now you retrieve these data for the next iteration, then your second combination is the second row of the same 8 cols and so forth .
so the first N combinations giving you the smallest sum is the N first rows (and do the sum along the cols direction)
回答(1 个)
Prateekshya
2024-7-8
编辑:Prateekshya
2024-7-8
Hi Jianwei,
I understand that you want to retrieve the first 1000000 combinations of 8 elements coming from each column. You may use the MATLAB function "nchoosek" for this purpose. Please follow this link to know more about it:
I hope it helps!
Thank you.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!