how many ways to arrange numbers from 1-3?
1 次查看(过去 30 天)
显示 更早的评论
how many ways to arrange numbers from 1-3?
I want answer like this
[1,1,1]
[1,1,2]
[1,1,3]
[1,2,1]
[1,2,2]
[1,2,3]
[1,3,1]
[1,3,2]
[1,3,3]
[2,1,1]
[2,1,2]
[2,1,3]
[2,2,1]
[2,2,2]
[2,2,3]
[2,3,1]
[2,3,2]
[2,3,3]
[3,1,1]
[3,1,2]
[3,1,3]
[3,2,1]
[3,2,2]
[3,2,3]
[3,3,1]
[3,3,2]
[3,3,3]
Can you please put these values in one matrix?
0 个评论
采纳的回答
Walter Roberson
2015-10-13
[A,P,Z] = ndgrid(1:3);
[Z(:), P(:), A(:)]
2 个评论
Walter Roberson
2015-10-16
编辑:Walter Roberson
2015-10-16
N = 5;
[A{1,1:N}] = ndgrid(1:N);
Result = cell2mat( cellfun(@(V) V(:), fliplr(A), 'Uniform', 0) );
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!