| Description |
CIRCULANT - Circulant Matrix
C = CIRCULANT(A) or CIRCULANT(A,1) returns the circulant matrix C based
on the vector A. C is a square matrix in which each row (or column) is
a formed by circularly shifting the preceeding row (or column) forward
by one element. The first row (or column) is given by the row- (or
column-)vector A. The last row (or column) will therefore be the input
in reversed order.
C = CIRCULANT(A,-1) applies a backward shift, returning a symmetric
matrix, so that C equals TRANSPOSE(C).
Examples:
circulant([2 3 5 7]) % forward shift
% -> 2 3 5 7
% 7 2 3 5
% 5 7 2 3
% 3 5 7 2
circulant([2 3 5 7], -1) % backward shift
% -> 2 3 5 7
% 3 5 7 2
% 5 7 2 3
% 7 2 3 5
circulant([2 3 5 7].') % column input
% -> 2 7 5 3
% 3 2 7 5
% 5 3 2 7
% 7 5 3 2
circulant([2 3 5 7].', -1) % column input, backward shift
% 2 3 5 7
% 3 5 7 2
% 5 7 2 3
% 7 2 3 5
The output has the same type as the input, and can e.g. be cell arrays:
circulant({'One','2','III'})
% -> 'One' '2' 'III'
% 'III' 'One' '2'
% '2' 'III' 'One'
Notes:
- This version is completely based on indexing and does not use loops,
repmat, hankel, toeplitz or bsxfun. It should therefore run pretty
fast on most Matlab versions.
- See http://en.wikipedia.org/wiki/Circulant_matrix for more info on
circulant matrices.
See also toeplitz, hankel
latsq, ballatsq (on the File Exchange) |