0

在这里的上一个问题上对最后一行代码中为示例给出的答案进行采样仅返回 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 问题的尝试,如果有人能想出更好的“工作方式”的话。

4

1 回答 1

3

怎么样

 sample = sample(randperm(1000),:);
于 2012-11-13T20:57:13.467 回答