how many ways to arrange numbers from 1-3?

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?

 採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 13 日

1 投票

[A,P,Z] = ndgrid(1:3);
[Z(:), P(:), A(:)]

2 件のコメント

Ali Noori
Ali Noori 2015 年 10 月 16 日
thank u can u send me code to arrange number from 1-5
Walter Roberson
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 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2015 年 10 月 13 日

回答済み:

2015 年 10 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by