shpf.m

来自「包含大量遗传算法程序」· M 代码 · 共 36 行

M
36
字号
function f=shpf(x,m,n)
%SHPF   Reshape matrix into MVFR matrix
%       SHPF(X,m)  reshapes the columns of X into an MVFR matrix
%       with square component matrices m-by-m.
%       X is a matrix with one column per element of the MVFR matrix
%       and one row per frequency. Each row is reshaped into a
%       component matrix using A(:) where A=eye(n).
%
%       SHPF(X,m,n) reshapes the rows of X into component matrices
%       with m rows and n columns.
%
%       SHPF(X,A) reshape the row of X into component matrices the
%       same size as A.
%       See also FGET

%       Dr M.P. Ford 4th August 1987
% Copyright (c) 1987 by GEC Engineering Research Centre & Cambridge Control Ltd

nargs=nargin;
error(nargchk(2,3,nargs));
[mx,nx]=size(x);
if nargs==2
   a=eye(m);
else
   a=eye(m,n);
end
[m,n]=size(a);
if m*n~=nx
   error('Size not consistent with number of columns of X')
end
k=1:m;
for i=0:mx-1
   a(:)=x(i+1,:);
   f(k+i*m,:)=a;
end

⌨️ 快捷键说明

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