Nice simple function, and I should point out that it will work with the basic Matlab package. The Communications System Toolbox is not required, despite what is indicated above.
To make it clear for anyone who is new to the concept of decibels, the output decibels of this function are not the same as the acoustic decibels we tend to think of. This function works for power or intensity, but not for field amplitudes such as sound pressure level. Also, input should be a dimensionless number such as a fraction of (power)/(reference power).
If you want a function for decibels of sound pressure level, there's one on the file exchange site here: http://www.mathworks.com/matlabcentral/fileexchange/35876