How to create an N-ary array
2 次查看(过去 30 天)
显示 更早的评论
Suppose I have K variables, each of which can take the values 1 through N. I want to create a table such that each column corresponds to the Kth variable, and each row corresponds to a particular combination. This table will be N^K entries long and K entries wide. One way to do this would be, for example
[V1 V2 ... VK] = ngrid(1:N,1:N,...,1:N)
V = [V1 V2 ... VK]
However, this clearly does not generalize nicely to variable N. Is there a simple way to extend this code so it works for different K?
8 个评论
James Tursa
2020-12-18
编辑:James Tursa
2020-12-18
OK, got it. Looks like you are basically counting in base N with K digits. How large can K and N be? This could easily eat all your memory if they are too large.
回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!