fixed for both mex and matlab