如何使用randperm选择m-by-n数据矩阵并输出该随机数据的较小子集?
即
newfile = randperm(data(m = 2000, n = 3)); %% save random m-by-n data as newfile
答案 0 :(得分: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);