1

需要选择W_tot_migl矩阵的随机行。现在我正在这样做:

[m, n] = size(W_tot_migl); % m data points, n dimensions
randomPoints = [];
for i=1:14250
     index = random('unid', m); % Pick the index at random.
     randomPoints(i,:) = W_tot_migl(index,:); % Add random point.
     W_tot_migl(index,:) = []; % Delete selected row.
     m = m-1;
end

有没有更快的方法,也许可以避免循环?

4

1 回答 1

1

这是一种更 matlab 的方法:

nr = 5; %How many do you want to pick

n = size(W_tot_migl,1); 
idx = randperm(n,nr);

randomPoints = W_tot_migl(idx,:);
W_tot_migl(idx,:) = [];

请注意,当您一次选择它们时,您无需担心重复。如果这是从原始文件中删除它们的唯一原因,那么最后一行现在已经过时了。

于 2013-10-08T12:46:37.243 回答