Thank you for sharing this. I modified based on this to calculate normalized mutual information. However, I found the results could be larger than 1 sometimes (which is wrong). I checked my modified part and everything is correct, which means the mutual information given by this code could be wrong or not accurate. I checked the code and found that it is mainly caused by different definition of bin boundary of hist (matlab defined) and hist2 (user defined). I replaced hist() with following myhist() and the result is now excellent on simulated toy testing data.