Funny. Actually, both of the other answers have missed an important point. While they properly describe how to use discretize, both Star and Adam got the class boundaries wrong. :) What they did not notice was the classes described as 1:4, 5:9, etc are not equal in width. So using colon to create classes as they did will create the wrong class bounds.
Assume you want 1-4 in class 1, 5-9 in class 2, 10-14 in class 3, 15-19 in class 4, etc. You only told us what the first two classes were, so I cannot be sure. But both Adam and Star said to use bin edges of 1:4:29.
1 5 9 13 17 21 25 29
The bins should be a list of the LOWER bounds for each class.
So 1:4:29 as the bin edges will put 5 and 9 in DIFFERENT classes.
Instead, the correct set of bin edges would have been something like 1 5 10 ...
I'll suggest that instead, the bin edges might properly have been 0:5:30.
g = discretize(data, 0:5:30);
That makes the first bin go down to 0, but who cares? Since you never have a point at 0, that it starts at 0 is irrelevant. Otherwise, if your boundaries are unequal in width all the way, you might do something like this:
g = discretize(data, [1 4 10 17 20 23 30]);