⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 circularmatrix.m.txt

📁 Computes the circulant matrix of a vector.
💻 TXT
字号:
%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
%
%   Example:
%      v = [ 1 2 3 4 ];
%      circulant( v )
%
%      ans =
%
%      1     2     3     4
%      2     3     4     1
%      3     4     1     2
%      4     1     2     3


function out = circulant( in )

vec = in;
x=0;y=0;

% Check if column vector
n_dims = ndims( vec );
if n_dims == 1
    vec = vec';
elseif n_dims == 2
    [x,y] = size(vec);
    if y~=1
        if x==1
            vec = vec';
        else
            error( 'ERROR: The input must be a vector' );
        end
    end
else
    error( 'ERROR: The input must be a vector' );
	return;
end

[x,y] = size(vec);

out = zeros( x, x );

out(:,1) = vec;
for i=1:x-1
    out(:,i+1) = circshift(out(:,i),-1);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -