random

조회 수: 4 (최근 30일)
Niki
Niki 2012년 6월 6일
I have a Matrix as follows
x = [1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20];
I want to generate a matrix from it that will be for example 100 combination of each element but for example for the first iteration, from first colum only one of them select then from the second as well then from the third as well and untill the end
so I may have like this
x = [ 6 2 18 4 20
16 17 3 4 10
and so on

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 6월 6일
x = [1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20];
EDIT after Mohammad's coment
[m,n] = size(x);
df = bsxfun(@plus,fullfact(m*ones(1,n)),(0:n-1)*m);
k = randperm(size(df,1));
out = x(df(k(1:min(100,numel(k))),:));
OR
[m,n] = size(x);
xc = mat2cell(x,m,ones(n,1));
cc = cell(1,n);
[cc{:}] = ndgrid(xc{:});
k = randperm(numel(cc{1}));
out = cell2mat(cellfun(@(x)x(k(1:min(100,numel(k)))'),cc,'un',0));
  댓글 수: 3
Niki
Niki 2012년 6월 6일
I want to have something lets say, number of permutation , can you also tell me what should I do with that?
for example I want to have only 100 generated row
more or less
Andrei Bobrov
Andrei Bobrov 2012년 6월 6일
full number of permutation for matricies with size m x n : N = m^n

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by