File Exchange

image thumbnail

Circular Matrix computation

version (1.36 KB) by Massimo Fierro
Commodity function for building a circulant matrix given a vector


Updated 02 Feb 2009

View License

circulant Computes the circulant matrix of a vector.

circulant(vec) is a max(size(vec))-by-max(size(vec)) circulant
matrix built with the elements of vec

Note: The parameter may be either a column or row vector

v = [ 1 2 3 4 ];
circulant( v )

ans =

1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3

Comments and Ratings (7)

Jos (10584)

The author should be commended for adding a good help section. Although faster and better algorithms exist, I concur with Husam A. that this is indeed a nice effort, and therefor happily raise my rating.

Don't listen to these elitists.
Good work and nice effort.

Thanks Jos for the comment, I didn't know about the hankel function.
Had I known, I would have definitely done it that way (as indexing always works better in Matlab).

I am quite surprised, though, that there is no function in the standard library for producing such a common matrix.

Jos (10584)

Some indexing will give you the same result
V = IN(:) ;
idx = hankel(1:numel(V),0:numel(V)-1)
% idx = hankel(1:numel(V)) + hankel(zeros(1,numl(V)),0:numel(V)-1)
OUT = V(ix) ;

Authors should not pad the star rating of their submissions.

I will gladly do, but I thought that the description "The function accepts both column and row vectors and produces the circulant matrix associated." would suffice.

Jos (10584)

Please add a proper help section including a H1 line, syntax and example. At present this submission is completely useless for anyone but the author.


Slightly modified the help and matched the file description with it

UPDATE Feb 02, 2009: added help

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Inspired by: Hysteresis Thresholding

Inspired: Circulant matrix, CIRCULANT (v2.0, feb 2009)

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor