choosing random vectors for 3 VAriables

i have made a vector like this x(1,i), i=1 to 10e6 in a m.file(this is my output format ) now i want to choose randomly 10000 of them and then showing those vectors. i have 3 random variables that all of them produced in a format like [x(1,i), i=1 to 10e6 ] now what should i do if i want to have in my output 10e4 randomly selected for each 3 variables??i mean 10e4 vectors (selected randomly) for my 3 variables.

 Accepted Answer

I don't understand 100% of your question but I will try
x1=randperm(10e6); %generates a permutation of values from 1 to 10e6
x2=x1(1:10e4); %get only the first 10e4 values
%replace x1 in the second line by your vector if needed

1 Comment

And repeat Paulo's operation for the three variables. If you want all three variables to contain unique entries from x, then use x1 = randperm(10e6);x2 = x1(1:3*10e4) and extract each x2(1:10000);x2(10001:20000);etc.

Sign in to comment.

More Answers (1)

If you do this once, Paulo's solution is fine. If you have to do this 1000s of times, it might be a problem that RANDPERM(10e6) takes 13 seconds (on my old 1.5GHz PentiumM). Then you could use the faster FEX: Shuffle:
Index = Shuffle(10e6, 'index', 10e4);
This replies 10e4 indices taken randomly out of 1:10e6 as the RANDPERM command, but it needs 0.05 seconds olny.
Nevertheless, the question is not getting clear to me also. Please give an example for the values of the 3 variables.

6 Comments

my 3 variables were produced by a m.file.this MATLAB code selects randomly values in a limited zone .this is code :
This function will generate a normal distribution conditional by bounds:
http://www.mathworks.com/matlabcentral/fileexchange/23832-truncated-gaussian
now i have to run this code 3 times to produce 3 vectors by this format x(1,i), i=1 to 10e6 >> for my 3 variables x,y,z.but i want to pick up randomly (not the first*) 10e4 of that 10e6 for each of my variables x,y,z.
"(not the first*)"
if you have a vector with numbers from 1 to 10e6 (values increasing with the index) and you do randperm you get those values but "shuffled" (without any specific order), now you pick the first 10e4 values of the "shuffled" vector, those 10e4 were picked up randomly!!
because of my bad explanation there is some misunderstanding.here is an example : x variable is located in limited zone[6.8,13.6]above MATLAB code generates 10e6 random numbers between that zone and put them in a vector by this format x(1,i), i=1 to 10e6>> it gives us each time random value without order it means maybe value of x(1,1000)to be smaller than x(1,10) because of randomly selecting.and then i want to pick up randomly 10e4 values of 10e6. for each x(1,10e6),y(1,10e6) and z(1,10e6).it means at the end i have 3* 10e4 randomly picked up of each variables (x,y,z)
Of course not the first 10e4. Did you try the solutions we have posted?!
would u please tell me how should i make a m.file with respect to this code :
This function will generate a normal distribution conditional by bounds:
http://www.mathworks.com/matlabcentral/fileexchange/23832-truncated-gaussian
to make that solution run???
The question is still vague. Therefore I have to guess:
X = TruncatedGaussian(sigma, range, 1e7);
var1 = X(Shuffle(1e7, 'index', 1e5));
var2 = X(Shuffle(1e7, 'index', 1e5));
var3 = X(Shuffle(1e7, 'index', 1e5));
Or if the variables are not allowed to have common elements:
Index = Shuffle(1e7, 'index', 3*1e5);
var1 = X(Index(1:1e5));
var2 = X(Index(1e5+1:2*1e5));
var3 = X(Index(2*1e5+1:3*1e5));
Note: I've use the standard method "1e5" instead of your notation "10e4", which means "10.0 * 10^4".
If you want something else, please take the time to formulate all inputs and outputs exactly.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!