MATLAB: How do you create a matrix Aij where each value is determined by a formula

arrayarrayscell arraysMATLABmatrixmatrix array

Eg: Aij = (-1)^i+j
Where i and j are the row and column indexes respectively.
So a 2 dimensional matrix, A, would be:
A =
1 -1
-1 1

Best Answer

[I,J] = ndgrid(1:2,1:2);
(-1).^(I+J)