Contents | Previous | Next | Subchapters |

Syntax |
`ghist(` y`) ` y`, ` nb`) ` y`, ` nb`, ` color`) ` y`, ` nb`, ` color`, ` cindex`)` |

See Also | gstair , gbar |

Plots a histogram with optional specification of the number of bins, the color, and grouping of elements by color. The histogram is scaled so that the height of each bin corresponds to the sample density for that bin. The size of the bins are adjusted to have the same number of samples in each bin with the exception that bins in the center may have one less sample than bins at the ends. If all of the entries in a bin have the same value, the entries are plotted as one cross for each entry above the value.

The real or double-precision column vector

If integer scalar

If the character matrix

If the integer column vector *y*(*i*)

corresponds to the color *color*.row(*cindex*(*i*))

.
Each element of If you enter

```
```

y = rand(499, 1)

nb = 20

ghist(y, nb)

O-Matrix will plot a histogram of 499 samples
that are uniformly distributed between zero and one.

The following program plots a similar histogram in
which the even indices correspond to "green"
and the odd indices correspond to "red".
```
```

clear

#

y = rand(499, 1)

nb = 20

color = {"red", "green"}

even = mod(seq(499), 2) == 0

odd = not even

cindex = odd % fill(1, 499, 1) + even % fill(2, 499, 1)

ghist(y, nb, color, cindex)