add rearrange matlab codes