Using matlab features for inner loop.