This is one of those question that are almost impossible to answer, because your goal is so fuzzy, too unclear to write code to solve. You want a set of 6 disctint values from the set, randomly chosen, such that they are not too close to the mean, yet are not too far away. And worse, the real problem that you have is not the one you show, and is of course much larger.

The problem is that only you know what you mean by those fuzzy, loose descriptions.

So what you need to do is to quantify how you would know IF a set of numbers was poorly chosen. What does that mean to YOU?

Once you can do that, then there is a simple algorithm you can use.

Use randperm to choose a set of 6 random indices into that matrix. Then apply your measure to the set of values as chosen. Are thay adequate? If so, then you are done. If not, then choose another set of 6 random indices. Repeat until you are happy, or better yet, until your measure of gooodness is satisfied. But remember, only you can write that function that identifies if some set is good, because only you knows what you mean by not too close, not too far.

You may wonder how randperm can choose 6 sets of subscripts. But in reality, you have just 24 numbers there to choose from. For example, if we use randperm to choose 6 numbers from the integers 1:24, without replacement, we might get this:

set = randperm(24,6)

set =

21 9 15 19 13 24

MATLAB can use this single indices to index into a 2-dimensional matrix, as such...

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.