Fixed logic for matlab :)