MATLAB: How to re-assign index values for a matrix

indexingmatrix

I have a 6×6 matrix that, instead of being indexed from 1-6, I want to assign a vector to index the matrix.
For example,
k =
1 3 5 6 3 1
5 6 7 3 4 5
1 3 4 5 7 4
1 4 6 7 8 9
1 7 6 5 4 3
1 2 3 4 5 6
v =
7
8
11
12
13
14
How can I assign the values of v as the index to the rows of k?
And then, >> v'
ans =
7 8 11 12 13 14
as the index for the columns of k?
So that k(7,7)= 1 and k(14,14)= 6 and k(11,11)= 4

Best Answer

The mapping turned out to be simpler and more straightforward than I thought. I was overthinking it.
The mapping function:
y = @(x,n) ceil(mod(x,n+0.1)); % Mapping Function: x = Index, n = Row (Column) Size Of Square Matrix
Example:
x = 1:44
n = 6;
idx = y(x,n)
x =
Columns 1 through 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Columns 16 through 30
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Columns 31 through 44
31 32 33 34 35 36 37 38 39 40 41 42 43 44
idx =
Columns 1 through 15
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3
Columns 16 through 30
4 5 6 1 2 3 4 5 6 1 2 3 4 5 6
Columns 31 through 44
1 2 3 4 5 6 1 2 3 4 5 6 1 2
... and specifically:
x = [7,24,30,36,40,44];
idx =
1 6 6 6 4 2
Also, when I tested it, it works for every n>1.