This paper introduces a generic dynamic programming function for Matlab. This function solves discretetime optimal-control problems using Bellman's dynamic programming algorithm. The function is implemented such that the user only needs to provide the objective function and the model equations. The function includes several options for solving optimal-control problems. The model equations can include several state variables and input variables. Furthermore, the model equations can be time-variant and include time-variant state and input constraints. The syntax of the function is explained using two examples. The first is the well-known Lotka-Volterra fishery problem and the second is a parallel hybrid-electric vehicle optimization problem.