I am working on a large Matlab test node with thousands of lines of code, and I am trying to optimize the most time-consuming procedures defined through the Matlab profiler. I noticed that one of those most labor-intensive operations is as follows:
list = list((list(:,1) >= condxMin) & (list(:,1) <= condxMax) & (list(:,2) >= condyMin) & (list(:,2) <= condyMax),:);
Specifically, I have a large list of coordinates (at least 50,000 x 2), and I want to limit the values ββof this list to save only those points that check both of these conditions: the list (:, 1) must be within [condxMin, condxMax] and list (: 2) inside [condyMin condyMax].
I was wondering if there was a more efficient way to do this, given that this line of code is already vectorized. Also, I am wondering if Matlab is making a short circuit or not. If this is not the case, then I donβt think there is a way to do this without breaking the vectorization, and do it with a while loop, where I would write something like this instead:
j=1; for i=1:size(list,1) if(cond1 && cond2 && cond3 && cond4) newlist(j,1:2) = list(i,1:2); j=j+1; end end
Thank you in advance for your reply :)
source share