Code covered by the BSD License  

Highlights from
CIRCULANT (v2.0, feb 2009)

5.0
5.0 | 3 ratings Rate this file 8 Downloads (last 30 days) File Size: 2.29 KB File ID: #22876 Version: 1.3

CIRCULANT (v2.0, feb 2009)

by

Jos (10584) (view profile)

 

03 Feb 2009 (Updated )

(yet another, but fast) Circulent Matrix

| Watch this File

File Information
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)

Acknowledgements

Circulant Matrix inspired this file.

MATLAB release MATLAB 7 (R14)
Other requirements should work on almost any matlab release
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
14 May 2009 Massimo Fierro

Massimo Fierro (view profile)

 
07 Feb 2009 Jos (10584)

Jos (10584) (view profile)

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

Comment only
06 Feb 2009 Husam Aldahiyat

Wow.

05 Feb 2009 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
05 Feb 2009 1.1

acknowledge both FEX ID 22814 and 22858

07 Feb 2009 1.2

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

09 Feb 2009 1.3

Multiple acknowledgements added

Contact us