help-octave
[Top][All Lists]

## Re: counting totals in square grids (meshgrid)

 From: Isak Delberth Davids Subject: Re: counting totals in square grids (meshgrid) Date: Mon, 14 Dec 2009 10:38:32 +0000

```Let me take some time digesting this one and studying the accumarray
function --- thanks!
____________________________________________________________

> On Mon, Dec 14, 2009 at 11:12 AM, Isak Delberth Davids
>> I see, that last question of mine was really not needed, because value
>> of grid(i,j) is exactly equal to the number of elements that are in
>> the i-j-th grid. What more do I want there? My question was unclear
>> and aboveall, it was unnecessary. Jaroslav, thanks for the assistance!
>>
>
> Good.
>
>> Now back to improving the efficiency of the lines:
>> for i = 1:n
>>         for j = 1:n
>>                 grid(i,j) = sum (i-1 <= x & x < i & j-1 <= y & y < j);
>>         end
>> end
>>
>> Do you have a suggestion?
>>
>
> You can do something like this (not tested):
> i = floor (x);
> j = floor (y);
> mask = i > 0 & i <= n & j > 0 & j <= n;
> grid = accumarray ([i,j](mask,:), 1, [n, n]);
>
> see "help accumarray"
>
> --
> RNDr. Jaroslav Hajek
> computing expert & GNU Octave developer
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
>

--
***************************************************
***************************************************

FULL NAME: Isak Delbert Davids
LOCATION: mostly within 10cm of a keybord
CONTACTS: do not use contact lenses yet
FAX: still has a paper jam

"Views and opinions expressed by my person, are not necessarily true
--- they are simply my views and opinions"

***************************************************
***************************************************

```