[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Another vectorisation question
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: Another vectorisation question |
Date: |
Fri, 16 Jul 2010 00:15:52 -0500 |
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
Re: Another vectorisation question, Jaroslav Hajek, 2010/07/16