# 矩阵，当行和列均为奇数或偶数时为1

##### 问题描述投票：0回答：2

• 如果行是奇数而列是奇数，则值为1
• 如果行是偶数而列是偶数，则值为1
• 否则为0。

`````` N=8;
A = zeros(N);

for row = 1:1:length(A)
for column = 1:1:length(A)
if(mod(row,2) == 1 && mod(column,2) == 1)

A(row,column*(mod(column,2) == 1)) = 1;

elseif(mod(row,2)== 0 && mod(column,2) == 0 )

A(row,column*(mod(column,2) == 0)) = 1;

end
end
end
disp(A)
``````

`````` 1     0     1     0     1     0     1     0
0     1     0     1     0     1     0     1
1     0     1     0     1     0     1     0
0     1     0     1     0     1     0     1
1     0     1     0     1     0     1     0
0     1     0     1     0     1     0     1
1     0     1     0     1     0     1     0
0     1     0     1     0     1     0     1
``````
matlab matrix
##### 2个回答
0

``````N=8;
A = zeros(N);
A(1:2:end, 1:2:end) = 1;
A(2:2:end, 2:2:end) = 1;
``````

``````A = repmat([1, 0; 0 1], [N/2, N/2]);
``````

0

``````odd+odd = even+even = 0
``````

``````A = 1 - mod( (1:N) + (1:N).', 2 );
``````

``````A = toeplitz(mod(1:N,2));
```如果行数（`M`）不等于列数（`N`），则```
``````A = toeplitz(mod(1:M,2),mod(1:N,2))
```FWIW，您正在询问此问题的特定情况：```

How to generate a customized checker board matrix as fast as possible?