2012-11-13 20 views
0

上一個問題在這裏Sampling給出的最後一行代碼樣本的答案只返回1000x1而不是1000x6?randperm的多列

%% 
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問題的嘗試,如果任何人都能想出更好的方式「一種工作方式」。

回答

3

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

感謝如何dustincarr,現在工作得很好。 –