help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another vectorisation question


From: John Reed
Subject: Re: Another vectorisation question
Date: Fri, 16 Jul 2010 09:08:20 -0700

>>>> Jordi Gutiérrez Hermoso <address@hidden> 7/15/2010 10:15 PM
>>>
> On 15 July 2010 20:24, John Reed <address@hidden> wrote:
>> I am looking at a nearest neighbor problem.
>
> What exactly is the problem you want to solve? Do you want to count
> the number of points within each square in a regular grid? Or given
a
> point, do you want to be able to quickly know in which grid square
> it's found? When you said "nearest neighbour", the first thing I
> thought of was "quadtree", but you don't seem to form anything like
> that.
>
>> Is there a way to vectorise either of these approaches? Or is there
>> some totally different approach that would give me the answer I
want
>> without for loops?
>
> If all you want is a hist2d, you can either use that (it's in the
> 'Forge), or look at the bottom sample code that I distilled from it.
>
> I don't really get what you were trying to do with coords_to_grid,
but
> if you just want to know where on the grid a particular (x,y) pair
is,
> you just have to look at its corresponding (xidx,yix).
>
> HTH,
> - Jordi G. H.
>
>
----------------------------------------------------------------------
>
> incr = 70;
> pt_num = 40000;
> x=incr*rand(pt_num,1);
> y=incr*rand(pt_num,1);
>
> tic;
> histo_edges = [-0.5:1:incr+.5];
>
> xidx = lookup(histo_edges,x);
> yidx = lookup(histo_edges,y);
>
> num_pt_per_grid = full(sparse(xidx,yidx,1,incr+1,incr+1));
> toc

Thank you for the feedback Jordi,  I want to look up a certain grid
point and quickly find the indices of all the random x,y coordinates
that fall closest to that grid point.  
- John




reply via email to

[Prev in Thread] Current Thread [Next in Thread]