actually I have solved my problem in another way, but I am very interested to see how to amend this function
about random again
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2012-6-12
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).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!