A=1:12 while ~isempty(A) B=ceil(sqrt(randi([numel(A)]))) C=A(randsample(length(A),B)) [~,idx]=find(ismember(A,C)) A(idx)= end
The above code executes. but the outcome of B need to be increased subsequently,which means for first time B=1,next B=2,B=3 until B does not satisfy the subsequent condition.When b does not satisfy the subsequent condition,then B needs to start second time from beginning in such a way again B=1,B=2,B=3.In second time as A is 12,B can be 1 but B cannot be 2,so B needs to be treated again as 1.Similarly i need to run the code when i Change the value of A to 24,36 and so on.Could anyone help me to solve the issue.
I think I understand what you mean. If I do, then the code below should work for you.
A=1:12; B=0; while ~isempty(A) B=B+1; if B>numel(A),B=1;end C=A(randsample(length(A),B)); [~,idx]=find(ismember(A,C)); A(idx)=; end