John D'Errico <derrico@flare.net> wrote in message <derrico-6ADAF4.07282424012002@news.newsguy.com>...
> This is just a binning problem.
>
> Assume you have data in vectors x,y,z. I'll
> assume they are column vectors.
>
> 1. Convert to polar coordinates. Don't worry
> about theta.
>
> r = sqrt(x.^2+y.^2);
>
> 2. Assume bin boundaries are in a vector, call
> it rbins. Determine which bins each point falls
> in. Use either histc or bindex (histc did not
> exist in version 5.2.1, so I put bindex up for
> download.) In either case, the code will look
> something like:
>
> i=bindex(r,rbins);
>
> (I can't post the code using histc because I am
> responding from a mac, and frozen on version 5.2.1.)
>
> 3. Use the function sparse to accumulate z and to
> count the number of points in each bin. Assume
> the top number in rbins exceeds all the data in r.
>
> nbins=length(rbins)-1;
> sumz=sparse(i,1,z,nbins,1);
> n=sparse(i,1,1,nbins,1);
>
> 4. Averaging over z is now simple. Note that
> if any bins had no points in them at all then
> you will see a NaN result from a 0/0.
>
> meanz=sumz./n;
>
> Hope this helps,
> John D'Errico
>
>
>
> In article <3C4F8CA0.9060003@ucla.edu>, Denis Schluppeck
> <schluppe@ucla.edu> wrote:
>
> > Hi there,
> >
> > I have what I think is a 'vectorisation' problem.
> >
> > I want to average/sum values that lie in circular bands,
> > i.e. at a certain distance from the center of an image.
> >
> > -- Or if you think about it in terms of polar coordinates:
> > collapse the image into a line plot, discarding the 'angle'
> > information...
> >
> > Any ideas?? My current code uses a loop [find points that satisfy
> >
> > ring_i < sqrt(x.^2 + y.^2) < ring_o
> >
> > where ring_i and ring_o are the inner and outer radii of the bands
> > and average over those points]
> >
> > As you can imagine, if you make the rings quite narrow, you have to go
> > through the loop many times - very slow...
> >
>
> --
>
Thank you very much, John.
That solved a similar problem I had (using [n,bin]=histc(~) instead of bindex).
MEP
> This is just a binning problem.
>
> Assume you have data in vectors x,y,z. I'll
> assume they are column vectors.
>
> 1. Convert to polar coordinates. Don't worry
> about theta.
>
> r = sqrt(x.^2+y.^2);
>
> 2. Assume bin boundaries are in a vector, call
> it rbins. Determine which bins each point falls
> in. Use either histc or bindex (histc did not
> exist in version 5.2.1, so I put bindex up for
> download.) In either case, the code will look
> something like:
>
> i=bindex(r,rbins);
>
> (I can't post the code using histc because I am
> responding from a mac, and frozen on version 5.2.1.)
>
> 3. Use the function sparse to accumulate z and to
> count the number of points in each bin. Assume
> the top number in rbins exceeds all the data in r.
>
> nbins=length(rbins)-1;
> sumz=sparse(i,1,z,nbins,1);
> n=sparse(i,1,1,nbins,1);
>
> 4. Averaging over z is now simple. Note that
> if any bins had no points in them at all then
> you will see a NaN result from a 0/0.
>
> meanz=sumz./n;
>
> Hope this helps,
> John D'Errico
>
>
>
> In article <3C4F8CA0.9060003@ucla.edu>, Denis Schluppeck
> <schluppe@ucla.edu> wrote:
>
> > Hi there,
> >
> > I have what I think is a 'vectorisation' problem.
> >
> > I want to average/sum values that lie in circular bands,
> > i.e. at a certain distance from the center of an image.
> >
> > -- Or if you think about it in terms of polar coordinates:
> > collapse the image into a line plot, discarding the 'angle'
> > information...
> >
> > Any ideas?? My current code uses a loop [find points that satisfy
> >
> > ring_i < sqrt(x.^2 + y.^2) < ring_o
> >
> > where ring_i and ring_o are the inner and outer radii of the bands
> > and average over those points]
> >
> > As you can imagine, if you make the rings quite narrow, you have to go
> > through the loop many times - very slow...
> >
>
> --
>
Thank you very much, John.
That solved a similar problem I had (using [n,bin]=histc(~) instead of bindex).
MEP