Sample from the previous sample, whole rows.

1 回表示 (過去 30 日間)
Ellie
Ellie 2015 年 8 月 12 日
回答済み: dpb 2015 年 8 月 12 日
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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by