fix bug in saving endpoint as mat files