I know how to use toeplitz function in MATLAB to create a circulant matrix of 1 D vector. However, I am trying to create a circulant block
For example, I have 3 matrices of size (2,2,3) where third dimension is R,G, B: Below I am showing the sample values of row and column of each matrix. First Matrix:
# 01 02
# 03 04
Second Matrix:
# 05 06
# 07 08
Third Matrix:
# 09 10
# 11 12
Now I want to create a circulant matrix which looks like this
# 01 02 05 06 09 10
# 03 04 07 08 11 12
# 09 10 01 02 05 06
# 11 12 03 04 07 08
# 03 04 09 10 01 02
# 05 06 11 12 03 04
Note, I want to be able to move the entire block of the matrix to the right in the subsequent lines, and not just the first line of the matrix. Please note, i want to preserve the third dimensions of these matrices w(which has color dimension in them)
Can someone tell me how to go ahead with it? I thought of making an array I already have a 3D matrix, and don't know how to make an array of the array here, if it will help at all.
References:
- Toeplitz command in MATLAB: https://www.mathworks.com/help/matlab/ref/toeplitz.html
- A Stackoverflow I was trying to understand but couldn't: Matlab: How to convert a matrix into a Toeplitz matrix (not yet sure if i answers my question)
The following code builds a linear index as the sum of two parts:
repelem), andrepmat).Applying this index to the original matrix produces the desired result.
This gives
To better understand how this works, see the outer and inner indexing patterns (and if needed read about linear indexing):