MATLAB: Change even column values only

matrix

I create 20*20 2D array of all ones. And then I want to change even columns to minus one. How can I change with builtin function?

Best Answer

A = ones(20);
A(:,mod(1:20, 2) == 0) = -1;