added up and down determination into matlab