# histr

Histogram for geographic points with equirectangular bins

## Syntax

```[lat,lon,num,wnum] = histr(lats,lons) [lat,lon,num,wnum] = histr(lats,lons,units) [lat,lon,num,wnum] = histr(lats,lons,bindensty) ```

## Description

`[lat,lon,num,wnum] = histr(lats,lons)` returns the center coordinates of equal-rectangular bins and the number of observations, `num`, falling in each based on the geographically distributed input data. Additionally, an area-weighted observation value, `wnum`, is returned. `wnum` is the bin's `num` divided by its normalized area. The largest bin has the same `num` and `wnum`; a smaller bin has a larger `wnum` than `num`.

`[lat,lon,num,wnum] = histr(lats,lons,units)` where `units` specifies the angle unit. The default value is `'degrees'`.

`[lat,lon,num,wnum] = histr(lats,lons,bindensty)` sets the number of bins per angular unit. For example, if `units` is `'degrees'`, a `bindensty` of 10 would be 10 bins per degree of latitude or longitude, resulting in 100 bins per square degree. The default is one cell per angular unit.

The `histr` function sorts geographic data into equirectangular bins for histogram purposes. Equirectangular in this context means that each bin has the same angular measurement on each side (e.g., 1º-by-1º). Consequently, the result is not an equal-area histogram. The `hista` function provides that capability. However, the results of `histr` can be weighted by their area bias to correct for this, in some sense.

## Examples

collapse all

Create some random latitudes.

```rng(0,'twister') lats = rand(4)```
```lats = 4×4 0.8147 0.6324 0.9575 0.9572 0.9058 0.0975 0.9649 0.4854 0.1270 0.2785 0.1576 0.8003 0.9134 0.5469 0.9706 0.1419 ```

Create some random longitudes.

`lons = rand(4)`
```lons = 4×4 0.4218 0.6557 0.6787 0.6555 0.9157 0.0357 0.7577 0.1712 0.7922 0.8491 0.7431 0.7060 0.9595 0.9340 0.3922 0.0318 ```

Bin the data in 0.5-by-0.5 degree cells (two bins per degree). The bins centered at 0.75°N are slightly smaller in area than the others. `wnum` reflects the relative count per normalized unit area.

```[lat,lon,num,wnum] = histr(lats,lons,2); [lat,lon,num,wnum]```
```ans = 4×4 0.2500 0.2500 3.0000 3.0000 0.7500 0.2500 2.0000 2.0002 0.2500 0.7500 3.0000 3.0000 0.7500 0.7500 8.0000 8.0006 ``` 