Reputation: 3
Lets say I have a sequence set of integer number from 1 to 85 in data:
data = [1:1:85];
If I choose removeselection = 0, answer should be equal to data (all number from 1 to 85).
If I choose removeselection = 1, answer should be 85 groups of data.
data1 = [2:1:85] %remove number 1;
data2 = data(:,2) = []; %remove number 2
data3 = data(:,3) = []; %remove number 3
.
.
.
data85 = data(85,:) = []; %remove number 85
If I choose removeselection = 2, answer should remove 2 number and generate 85(84) group of data.
If I choose removeselection = 84, answer should be 85 group consist of single number.
data1 = [1];
data2 = [2];
data3 = [3];
.
.
.
data85 = [85];
If I choose removeselection = 85, answer should be equal to 0
The function should enable user to put number of removeselection from 0 up to maximum numbers in data which is 85.
Please help me regarding the matter. I really stuck on this xD
Upvotes: 0
Views: 55
Reputation: 112699
Here's a solution in one line, using nchoosek
. But note that, as I stated in the comments, the number of groups of data may become very large.
data = [1:1:6]; %// example data
removeSelection = 3; %// how many data to remove
groupsOfData = data(nchoosek(data,numel(data)-removeSelection));
In the example, the result is:
groupsOfData =
1 2 3
1 2 4
1 2 5
1 2 6
1 3 4
1 3 5
1 3 6
1 4 5
1 4 6
1 5 6
2 3 4
2 3 5
2 3 6
2 4 5
2 4 6
2 5 6
3 4 5
3 4 6
3 5 6
4 5 6
If there are too many groups of data and you want to sample randomly (as you state in the comments), you can use randsample
:
randomGroupOfData = randsample(data,numel(data)-removeSelection);
Upvotes: 2