What's the fastest way to get the points I want out of a huge blob? In MATLAB I have a set of 5393280 points in the form of a decimal-valued vector (x,y,z). How do I represent them in a way that I can quickly collect all the points within some rectangular x-y domain?

Right now I'm representing them as a 3-column matrix, sorted by x-values, and using the following code to extract a rectangular region:

mtx_region = mtx_pointList( dxLowerBound &lt; mtx_pointList(:,1) &amp; ...
                            dxUpperBound &gt; mtx_pointList(:,1) &amp; ...
                            dyLowerBound &lt; mtx_pointList(:,2) &amp; ...
                            dyUpperBound &gt; mtx_pointList(:,2), : );


However, I suspect that this is slowing my code down considerably.

What is a better way?
Prefiltering all relevant x-values with a binary search could speed up the process.

[a,A]=myFind2(mtx_region(:,1),dxLowerBound,dxUpperBound);

xpoints=mtx_region(a:A,:);
mtx_region = xpoints(     dyLowerBound &lt; xpoints(:,2) &amp; ...
                            dyUpperBound &gt; xpoints(:,2), : );


Binary search on sorted arrays is already discussed here.

function [b,c]=myFind2(x,A,B)
a=1;
b=numel(x);
c=1;
d=numel(x);
while (a+1&lt;b||c+1&lt;d)
    lw=(floor((a+b)/2));
    if (x(lw)&lt;A)
        a=lw;
    else
        b=lw;
    end
    lw=(floor((c+d)/2));
    if (x(lw)&lt;=B)
        c=lw;
    else
        d=lw;
    end
end
end