File Exchange

image thumbnail

CIRCULANT (v2.0, feb 2009)

version 1.3 (2.29 KB) by

(yet another, but fast) Circulent Matrix

0 Downloads

Updated

View License

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)

Comments and Ratings (4)

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.

Updates

1.3

Multiple acknowledgements added

1.2

v2.0 - bug fixed for forward shifted vectors !!

1.1

acknowledge both FEX ID 22814 and 22858

MATLAB Release
MATLAB 7 (R14)
Acknowledgements

Inspired by: Circulant matrix

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video