about random again

1 vue (au cours des 30 derniers jours)
Niki
Niki le 12 Juin 2012
I have one matrix as follows X = rand(4,10)
I want to generate a matrix from X and in each row a variable should be randomly selected and all possible combination can be used. actually the following code works for a small set like d = rand(4,3) but i have problem when a larger set like above X = rand(4,10) used , please run this and let me know .
[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))),:));
  3 commentaires
Walter Roberson
Walter Roberson le 12 Juin 2012
Perhaps you could describe the "problem" ?
Niki
Niki le 12 Juin 2012
Yes,
actually when I generate my matrix like for example follows
X = rand(10,23)
then i get the size of my matrix
[m,n] = size(X);
then I do
df = bsxfun(@plus,fullfact(m*ones(1,n)),(0:n-1)*m);
I will get error as
??? Error using ==> zeros
Maximum variable size allowed by the program is exceeded.
Error in ==> fullfact at 33
design = zeros(ssize,cols,class(levels));

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 12 Juin 2012
If I calculate correctly, fullfact(m*ones(1,n)) creates m^n rows of output each of width n.
When X = rand(10,23) then you are asking for 10^23 rows each of width 23, and each element takes 8 bytes (double precision), so you are asking for (8*23) * 10^23 bytes of output. That would be about 2^84 bytes. That exceeds the largest variable that can be handled on a 64 bit operating system (2^64 bytes).
  1 commentaire
Niki
Niki le 12 Juin 2012
so what should I do to prevent such problem?
can you help me ?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by