first version of matlab function for Z and X