my code for Matlab (manual)