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 )
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
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.
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.
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
Inspired by: Hysteresis Thresholding
Create scripts with code, output, and formatted text in a single executable document.