Matlab 多列随机数

Matlab 多列随机数,matlab,Matlab,在前面的问题中,最后一行代码中给出的示例答案只返回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(s

在前面的问题中,最后一行代码中给出的示例答案只返回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));
这在一行上输出28000条记录,显然不是我想要的。然后我试着:

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问题的一次尝试

怎么样

 sample = sample(randperm(1000),:);
怎么样

 sample = sample(randperm(1000),:);