vec2str.m

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

M
35
字号
function str=vec2str(v,form)
%VEC2STR  Converts vector to string array.
%         VEC2STR(V,'form') returns a string array with
%         one row for each number in the vector, V.
%         The input argument 'form' is optional and specifies
%         the format for the number to string conversion.
%         If 'form' is missing the default ' %.4g' is used.
%         This gives a leading space befor the number.
%         See SPRINTF in a C manual for valid formats.

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

nargs=nargin;
error(nargchk(1,2,nargs));
if nargs==1
   form=' %.4g';
end
blank=' ';
str=sprintf(form,v(1));
lstr=length(str);
for i=2:length(v)
    st=sprintf(form,v(i));
    lst=length(st);
    if lst>lstr
       [m,n]=size(str);
       str=[str,setstr(blank.*ones(m,lst-n))];
       lstr=lst;
    else
       st=[st,setstr(blank.*ones(1,lstr-lst))];
    end
    str=[str;st];
end  % for i=1:length(v)

⌨️ 快捷键说明

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