Selecting a subset of a larger matrix with criteria
2 次查看(过去 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 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!