Contrived test data.
m1 = Array[k, {9, 9}]
{{k[1, 1], k[1, 2], k[1, 3], k[1, 4], k[1, 5], k[1, 6], k[1, 7], k[1, 8], k[1, 9]},
...
{k[9, 1], k[9, 2], k[9, 3], k[9, 4], k[9, 5], k[9, 6], k[9, 7], k[9, 8], k[9, 9]}}
Here is how to solve your problem with For-loops. m2
will be the matrix you want. You can substitute any 9 x 9 matrix for m1
and the code will still work.
m2 = ConstantArray[0, {2, 2}];
For[i = 1; ii = 1, i <= 9, i += 8; ii += 1,
For[j = 1; jj = 1, j <= 9, j += 8; jj += 1,
m2[[ii, jj]] = m1[[i, j]]]];
m2 // MatrixForm

But really, wouldn't it be simpler just to write
m2 = {m1[[1, 1]], m1[[1, 9]], m1[[9, 1]], m1[[9, 9]]}
or
m2 = {m1[[1, 1]], m1[[1, -1]], m1[[-1, 1]], m1[[-1, -1]]}
or perhaps
m2 = Extract[m1, Tuples[{1, 9}, 2]]
or
m2 = Extract[m1, Tuples[{1, -1}, 2]]
Table
andDo
will help you. $\endgroup$ – Henrik Schumacher Jun 2 '18 at 8:32k[[{1,9},{1,9}]]
might also do it (look upPart
). Note thatPrint
just prints and does not create a new matrix. $\endgroup$ – Henrik Schumacher Jun 2 '18 at 9:24