2011-10-16 122 views

回答

5

考慮這個例子:

data = rand(8,6); 
m = 4; 
n = 2; 

%# pick random rows 
indX = randperm(size(data,1)); 
indX = indX(1:m); 

%# pick random columns 
indY = randperm(size(data,2)); 
indY = indY(1:n); 

%# filter data 
data2 = data(indX,indY) 

注意R2011b介紹了一個更簡單的語法RANDPERM,讓你直接寫:

indX = randperm(size(data,1), m); 
indY = randperm(size(data,2), n); 
+0

運行完美了! –