Selecting a subset of a larger matrix with criteria
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I have a matrix that is Nrows x 150000 that includes a small number values that are less than or equal to -1. I would like to create a smaller Nrows x 100000 matrix that only includes values greater than -1 using a random subset of the remaining values in the larger matrix. It could also be the first 100000 values in each row that fit the criteria, but it cannot be, for example, the largest 100000 values, as this would introduce bias. Therefore, I have not been able to figure this it out by sorting the values. It is also complicated by the fact that each row has a different number of values that are <=-1, so I can't simply drop those values; it would create a matrix with different numbers of columns.
Please help! And thank you in advance. Noah
0 件のコメント
採用された回答
Hugo
2013 年 7 月 2 日
Dear Noah,
Suppose that A is your original matrix and B is the matrix you want to obtain. You could do something like this:
B=zeros(N,100000);
for ind1=1:N
u=A(ind1,A(ind1,:)>-1);
B(ind1,:)=u(randperm(length(u),100000));
end
The code chooses the elements randomly. The code is assuming that there are always more than 100000 values greater than -1. Otherwise, you will get an error in the fourth line.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で QPSK についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!