Matlab How Do I Vectorize This Code Stack Overflow

Matlab How Do I Vectorize This Code Stack Overflow