How to generate random vectors from given set of values?

6 views (last 30 days)
I have 30 different values. I want to generate possible maximum number of 3*1 vectors from those values with condition that two vectors don't have all same values. How i can store those generated vectors as data list in MATLAB? I need a function which takes 3*1 vector as an input and check whether this vector is exists in data list. If not then add it to data list, otherwise ignore it. What should i do ?
Thanks in advance for your help.

Answers (1)

KL
KL on 22 Oct 2017
Edited: KL on 22 Oct 2017
use randsample.
your_data = rand(30,1);
random_indices = randsample(numel(your_data),3);
your_random_mix = your_data(random_indices,random_indices);
To store different outcomes, well, it's only possible to generate 10 different combinations. Why not store them in a 3x10 matrix?
To make sure you get new samples everytime, exclude the elements you have already sampled and create a smaller your_data, sample the new 3 numbers from here.
Another suggestion is to shuffle the elements of your data and reshape it to 3x10. For example,
your_data = your_data(randperm(numel(your_data)));
your_samples = reshape(your_data,3,[]);

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!