Take samples from the previous sample

6 visualizaciones (últimos 30 días)
Ellie
Ellie el 10 de Ag. de 2015
Editada: Star Strider el 10 de Ag. de 2015
Hi all, I have set of data, the size doesn't really matter. Lets call it x1. I want to take a random set of values from x1 and lets call it x2. Then take random samples from x2 and call it x3. So on and so forth. I am not really sure how to do this, I have tried a couple of things, but without luck. Any help is appreciated. Also, I have access to the statistics library. The things that I have tried made use of the function randsample.
Thanks.
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 10 de Ag. de 2015
Can you give more details? how many sample? when do you want to stop?
Ellie
Ellie el 10 de Ag. de 2015
It doesn't really matter, but for arguments sake: sample size 100, and stop at 10.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 10 de Ag. de 2015
I’m not certain what you want, but this is one possibility:
x1 = randsample(99, 15)'
x2 = x1(randsample(15,10))
x1 =
76 68 83 17 87 16 35 30 53 62 26 38 8 98 40
x2 =
8 53 40 38 17 83 26 62 35 30
The only constraint is to be certain that in ‘x2’ and beyond, the first argument to randsample is not greater than the length of the vector created in ‘x1’ or the earlier vectors.
  2 comentarios
Ellie
Ellie el 10 de Ag. de 2015
That is the desired output, but how could I make it more general. For example, if I want to do that 10 times, I don't want to have to do that over and over.
Star Strider
Star Strider el 10 de Ag. de 2015
Editada: Star Strider el 10 de Ag. de 2015
One option is to put it into a loop:
x{1} = randsample(99, 15)';
for k1 = 2:10
x{k1} = randsample(x{k1-1},15);
end
All the vectors are the same sizes, but since they are cells, you can experiment with them to get the result you want.
EDIT — To use randsample with replacement, include the third argument as true or 1.

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 10 de Ag. de 2015
x=1:100
k=1;
out{k}=x
while numel(out{k})>10
n=numel(out{k});
idx=randperm(n-1);
out{k+1}=out{k}(idx);
k=k+1;
end
celldisp(out)
  2 comentarios
Ellie
Ellie el 10 de Ag. de 2015
Is there a way to do this with replacement?
And maybe without using cells?
Azzi Abdelmalek
Azzi Abdelmalek el 10 de Ag. de 2015
the new samples have different sizes, you can't avoid cells. Why do you want to avoid cells?

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by