MATLAB code for DIME calculation