Sample from the previous sample, whole rows.

1 次查看(过去 30 天)
Hi all,
My goal here is to combine these two codes that I have. The first code uses randsample from the statistics library, and I can use this, but I think it would be easier all around to try to incorporate the second block of code.
The first set of code works well, except that I am having trouble modifying it to sample whole rows of code. The second block of code does this, but only once.
Basically, I would like to take samples over and over. For example I want to find m2, which is sampled from m1. Then find m3, which is sampled from m2. So on and so forth. Ideally it would use the code below, and something that I could take n samples.
Ideally I would be able to use the things that I already have, but if there is a better way to go about it, then by all means.
Thanks in advance.
First Block:
x{1} = randsample(99, 15)';
for k1 = 2:10
x{k1} = randsample(x{k1-1},15);
end
Second Block:
m1 = rand(1000,10);
k = randi(1000,1, 1000);
m2 = m1(k(1:1000),:);

回答(1 个)

dpb
dpb 2015-8-12
Your second is simply another way for writing
m2=m1(randperm(1000),:)
If you're not regenerating m1 but simply rearranging, then one could simply preallocate a resulting array of (N,size(m1,2)) and populate it with the above in a loop or with accumarray or the like.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by