上一个问题Sampling在最后一行代码中给出的样本答案只返回1000x1而不是1000x6?
%%
normIdx = strmatch('normal.', Book2);
normalSubset = fulldata(normIdx, :);
normal = randperm(size(normalSubset , 1));
p = normal(1:750)-1;
%
smurfIdx = strmatch('smurf.', Book2);
smurfSubset = fulldata(smurfIdx, :);
smurf = randperm(size(smurfSubset , 1));
a = smurf(1:250)-1;
%
normalSample = normalSubset (p, :);
smurfSample = smurfSubset (a, :);
%
sample = [normalSample ; smurfSubset]
%
sample = sample(randperm(1000)); % this line
我试过了:
sample = randperm( size(sample, 1));
这一行输出28,000条记录,显然不是我想要的。然后我尝试了:
rows = 1000;
columns = 6;
%# pick random columns
indY = randperm( size(sample,2) );
indY = indY(1:columns);
%# pick random rows
indX = randperm( size(sample,1) );
indX = indX(1:rows)';
%# filter data
sample = [indX ; indY];
但我无法连接最后一行?这只是试图修复1000x6问题的尝试,如果有人能想出一个更好的方式“一种工作方式”。
答案 0 :(得分:3)
怎么样
sample = sample(randperm(1000),:);