0
如何使用randperm選擇數據的m乘n矩陣並輸出該隨機數據的較小子集?隨機m×n矩陣的randperm子集
即
newfile = randperm(data(m = 2000, n = 3)); %% save random m-by-n data as newfile
如何使用randperm選擇數據的m乘n矩陣並輸出該隨機數據的較小子集?隨機m×n矩陣的randperm子集
即
newfile = randperm(data(m = 2000, n = 3)); %% save random m-by-n data as newfile
考慮這個例子:
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);
運行完美了! –