Your second assignment in Example 1 (b = ones(size(a))) means that b no longer refers to the same matrix that a does. In Example 2 on the other hand, you are changing the elements of the matrix that b refers to, which a also refers to.
4 Likes