Simplifying for-find loop functions to speed up processing
1 次查看(过去 30 天)
显示 更早的评论
Hi all,
A pretty basic question, but I'm trying to find a more elegant solution to search through a 750,000x5 list to remove entries from a corresponding list when more than three value in any respective row are above a threshold of 10. The long way of doing so that I have is
% mD is a 750000 x 5 matrix containing distances to the nearest 5
% neighbors of the r,c,v point (from knnsearch) in each row
for i = size(r,1):-1:1
if size(find(mD(i,:)>10),2) > 3
r(i) = [];
c(i) = [];
v(i) = [];
end
end
4 个评论
Torsten
2024-1-26
Are there more than 3 values in mD row (i) above 10?
But you don't refer to row i of mD in your loop - you refer to the complete matrix mD with your find-command.
采纳的回答
Dyuman Joshi
2024-1-26
编辑:Dyuman Joshi
2024-1-26
I assume r, c and v have the same number of rows -
%Check which rows from the given range in mD have more than 3 values greater than 10
idx = sum(mD(1:size(r,1),:)>10, 2)>3
%perform deletion
r(idx) = [];
c(idx) = [];
v(idx) = [];
If all the variables have the same number or rows then you can remove the indices used and just use mD.
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!