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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by