how many ways to arrange numbers from 1-3?

조회 수: 2 (최근 30일)
Ali Noori
Ali Noori 2015년 10월 13일
답변: Jos (10584) 2015년 10월 16일
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일
[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개)

Jos (10584)
Jos (10584) 2015년 10월 16일
You might also be interested in PERMN: http://www.mathworks.com/matlabcentral/fileexchange/7147

카테고리

Help CenterFile Exchange에서 Signal Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by