As you know, vectorized programming has many advantage places. It's neat, effienct, sometimes it is very short and much easier than writing long tedious loops code. When manipulate matrix or data, it is heavily focused on index. The logical indexing in matlab made many operations easy. Using a single or logical array as matrix subscript can filter the data you want easily.
Below are two examples I encountered these days. Using logical index it is very easy.
1. Write a function called separate_by_two that takes a matrix A of positive integers as an input
and returns two row vectors. The first one contains all the even elements of A and noth