Object Recognition using bag of features using matlab
The, for now free available computer vision book, by Richard Szeliski contains an excellent introduction to this algorithm. Page 612. 

EDIT:

I answered a similar question here on DSP with some example code.