# [Matlab] Grid renumbering for Matrix

## Homework Statement

I have a matrix A $\in$ R$^{m x m}$ where m = n$^{2}$ and n = 2$^{k}$ +1, k= 0,...,L.
As in the image attached,the original numbering in the case k=1 is [ 1 2 3 4 5 6 7 8 9], i want the nodes to be renumbered
to a new numbering T=[2 4 5 6 8 1 3 7 9] (meaning position 2 in original comes first followed by position 4,etc.) and likewise for all k.

## The Attempt at a Solution

In the first case (9 nodes), i considered the original numbering and created a matrix in that format say Q = reshape(1:m,3,[])'.
i then considered the Union of both even rows and columns (for k=1, this is 2) i.e. G = (Q(2,:)$\cup$Q(:,2)). then
subsequently find the difference with the original, i.e. H= (Q-G).I then store them in a vector as [G H].

currently it works for k= 1,2 but not any further.
Any assistance will be appreciated.

Note:
From the attached image; Blue(first), Purple(second), gold (third).

k=1; T =[2 4 5 6 8 1 3 7 9]
k= 2; T= [2 4 6 7 8 9 10 12 14 16 17 18 19 20 22 24 3 11 13 15 23 1 5 21 25].

#### Attachments

• gridNumber.png
15.7 KB · Views: 491
Last edited: