File Exchange

## CIRCULANT (v2.0, feb 2009)

version 1.3 (2.29 KB) by

(yet another, but fast) Circulent Matrix

Updated

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.
circulant matrices.

latsq, ballatsq (on the File Exchange)

Massimo Fierro

Jos (10584)

### Jos (10584) (view profile)

An update that resolves a bug in forward shifts has been submitted. Please wait for version 2.0.

Husam Aldahiyat

Wow.

John D'Errico

### John D'Errico (view profile)

Efficient, well written, clean code. Excellent help, examples. Appropriate error checks. It offers either form of circulant matrix, with the proper choice of default.