Doesn't hist
already do the first one?
From help hist
:
N = HIST(Y) bins the elements of Y into 10 equally spaced containers
and returns the number of elements in each container. If Y is a
matrix, HIST works down the columns.
For the second look at help bar