From: Walter Roberson on
Jim O'Doherty wrote:
> Thanks for the point in the right direction Bruno. Does my data need to
> be sorted? My X, Y arrays are electron positions so they are not in any
> increasing/decreasing order. I seem to be getting an error saying it
> requires monotonically decreasing arrays

The specified edges would have to be sorted, but it should not be necessary to
sort the data to be binned.

You can do a 2D sort using sortrows() if you need to.


In your problem statement, you asked how to determine how often each pair of
X, Y occurred, which suggests that your X and Y are quantized values. In the
above note, you indicate that the X and Y are electron positions, which I
would not normally think of as quantized, at least not when using those
variable names (as the names are not suggestive of shell numbers or similar.)
Are your X and Y indeed quantized, or do you perhaps wish to quantize them?
If so, are the quanta regularly spaced? If so, then if you subtract off the
minimum values and divide by the quantum spacing and floor() the results, and
add 1, the results would be bin numbers that should then be relatively easy to
count (perhaps using accumarray)
From: Jim O'Doherty on
Hi, thanks for your replies. The X,Y daya is indeed quantised, and the values will always be integers, its simply a location in space coming from a detector face that I need to reconstruct. I've pasted a sample of my million points below. They won't be regularly spaced, or at least they shouldn't be. Basically I want to build up an image, so I wanted to know how often each pair of values occurs (i.e. bin by location) so I can somehow image it.

X Y
449 2741
2968 3511
2650 1990
1552 1122
1481 2698
3524 622
2649 1588
1204 1918
1972 2129
986 2140
1625 991
1120 1032
2395 2097
1935 3334
459 531
1907 1978
1341 1302
.. .
.. .
.. .
.. .
.. .

Jim



Walter Roberson <roberson(a)hushmail.com> wrote in message <i27mj3$cpc$1(a)canopus.cc.umanitoba.ca>...
> Jim O'Doherty wrote:
> > Thanks for the point in the right direction Bruno. Does my data need to
> > be sorted? My X, Y arrays are electron positions so they are not in any
> > increasing/decreasing order. I seem to be getting an error saying it
> > requires monotonically decreasing arrays
>
> The specified edges would have to be sorted, but it should not be necessary to
> sort the data to be binned.
>
> You can do a 2D sort using sortrows() if you need to.
>
>
> In your problem statement, you asked how to determine how often each pair of
> X, Y occurred, which suggests that your X and Y are quantized values. In the
> above note, you indicate that the X and Y are electron positions, which I
> would not normally think of as quantized, at least not when using those
> variable names (as the names are not suggestive of shell numbers or similar.)
> Are your X and Y indeed quantized, or do you perhaps wish to quantize them?
> If so, are the quanta regularly spaced? If so, then if you subtract off the
> minimum values and divide by the quantum spacing and floor() the results, and
> add 1, the results would be bin numbers that should then be relatively easy to
> count (perhaps using accumarray)
From: Walter Roberson on
Jim O'Doherty wrote:
> Hi, thanks for your replies. The X,Y daya is indeed quantised, and the
> values will always be integers, its simply a location in space coming
> from a detector face that I need to reconstruct. I've pasted a sample of
> my million points below. They won't be regularly spaced, or at least
> they shouldn't be. Basically I want to build up an image, so I wanted to
> know how often each pair of values occurs (i.e. bin by location) so I
> can somehow image it.
>
> X Y
> 449 2741
> 2968 3511
> 2650 1990
> 1552 1122

Ah, then supplying edges of 1:max(X) and 1:max(Y) should do the trick for the
N-dimensional histogram routine.

Possibly John D'Errico's "consolidator" FEX contribution would also be useful.


Looking back through some of my prior postings, I found an alternative
approach using accumarray.

This assumes that the minimum X and Y are 1:

maxx = max(x);
maxy = max(y);

xycounted = reshape( accumarray( sub2ind([maxx, maxy], x, y), 1 ), maxx, maxy);


You could then surf() or pcolor() or densityplot() that array.
From: Jim O'Doherty on
Ok, I see where you're going....
I ran the snippet of code for 1000 elements in X and Y and RESHAPE threw up an error saying that the number of elements must not change. Also when I ran it with only 4 elements in X and Y, I got xycounted to be a 2968 x 3511 array! Something amiss somewhere......
I'll check out the consolidator though, cheers

Walter Roberson <roberson(a)hus
hmail.com> wrote in message <i27p8n$gp0$1(a)canopus.cc.umanitoba.ca>...
> Jim O'Doherty wrote:
> > Hi, thanks for your replies. The X,Y daya is indeed quantised, and the
> > values will always be integers, its simply a location in space coming
> > from a detector face that I need to reconstruct. I've pasted a sample of
> > my million points below. They won't be regularly spaced, or at least
> > they shouldn't be. Basically I want to build up an image, so I wanted to
> > know how often each pair of values occurs (i.e. bin by location) so I
> > can somehow image it.
> >
> > X Y
> > 449 2741
> > 2968 3511
> > 2650 1990
> > 1552 1122
>
> Ah, then supplying edges of 1:max(X) and 1:max(Y) should do the trick for the
> N-dimensional histogram routine.
>
> Possibly John D'Errico's "consolidator" FEX contribution would also be useful.
>
>
> Looking back through some of my prior postings, I found an alternative
> approach using accumarray.
>
> This assumes that the minimum X and Y are 1:
>
> maxx = max(x);
> maxy = max(y);
>
> xycounted = reshape( accumarray( sub2ind([maxx, maxy], x, y), 1 ), maxx, maxy);
>
>
> You could then surf() or pcolor() or densityplot() that array.
From: Walter Roberson on
Jim O'Doherty wrote:
> Ok, I see where you're going....
> I ran the snippet of code for 1000 elements in X and Y and RESHAPE threw
> up an error saying that the number of elements must not change. Also
> when I ran it with only 4 elements in X and Y, I got xycounted to be a
> 2968 x 3511 array! Something amiss somewhere......
> I'll check out the consolidator though, cheers

>> This assumes that the minimum X and Y are 1:
>>
>> maxx = max(x);
>> maxy = max(y);
>>
>> xycounted = reshape( accumarray( sub2ind([maxx, maxy], x, y), 1 ),
>> maxx, maxy);

Ah, you might need to add .' after the sub2ind() call; the first parameter
must be a column vector.

Hmmm, looks like

xycounted = accumarray( horzcat(x(:),y(:)), 1);

would perhaps work just as well.

You should expect a fairly large output array -- one for each possible (x,y)
pair. If that isn't what you want, then you need to define more clearly how
you want the data to be imaged.

You may also wish to use scatter() to image the data.
First  |  Prev  | 
Pages: 1 2
Prev: convert arcgis grid to geotiff
Next: LVQ