MATLAB: How to make alternating signs on a matrix

alternatingmatrix

E=[1:4;6:9;11:14;16:19]
So I have this matrix, how can i make it so that the components come one with + sign and one with – sign, so alternating signs?
We just got started today with Matlab so sorry if it is a beginners question

Best Answer

Another approach:
E=[1:4;6:9;11:14;16:19];
m = (-1).^toeplitz((1:size(E,1)),(1:size(E,2))); % Multiplier Matrix
Out = E .* m
producing:
Out =
-1 2 -3 4
6 -7 8 -9
-11 12 -13 14
16 -17 18 -19
Create ‘Out’ by multiplying them in the same line if you want. (I kept them separate for clarity.)