参考链接:https://www.computationalimaging.cn/2020/01/matlab-train-test-val-inedx-number.html
功能:将[1,N]之间的整数随机抽1%写到val中; 1%写到test中; 其余写到train中
N = 10000;
A = [1:N];
A_temp = A;
val = [];
test = [];
% val
while length(val)<floor(N/100)
temp = 1+floor(N.*rand(1));
if ismember(temp,A_temp)
val = [val, temp];
A_temp = setdiff(A_temp,temp);
end
end
% test
while length(test)<floor(N/100)
temp = 1+floor(N.*rand(1));
if ismember(temp,A_temp)
test = [test, temp];
A_temp = setdiff(A_temp,temp);
end
end
% train
train = A_temp;
% sort()
test = sort(test);
val = sort(val);
train = sort(train);