필터 지우기
필터 지우기

expanding matrix

조회 수: 1 (최근 30일)
rahman
rahman 2011년 5월 16일
Hi all
I want to expand matrix.for example if x=[x1;x2] then the new matrix will be:
xx = [x1 x1 x1;x1 x1 x2;x1 x2 x1;x1 x2 x2;x2 x1 x1;x2 x1 x2;x2 x2 x1;x2 x2 x2]
How can I do that

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 5월 16일
[j k i]=meshgrid([x1,x2]);
xx = [i(:) j(:) k(:)];

추가 답변 (1개)

Matt Fig
Matt Fig 2011년 5월 16일
Here is a general purpose file for doing the same thing. What you are basically doing is finding the permutations of the set [x1 x2] taken three at a time with replacement. For example:
x1 = 7;x2 = 9; % Sample data
xx = npermutek([x1 x2],3);
xx =
7 7 7
7 7 9
7 9 7
7 9 9
9 7 7
9 7 9
9 9 7
9 9 9
NPERMUTEK is found here.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by