If you have matlab 2015, then you should use that version.
If you do not, then I'm fairly certain that copying code from it is a violation of your license (i.e. it's illegal). Plus, as you found out it does not work.
You cannot use histcounts in 2014a, you have to use the function it replaced: histc