set.m

来自「多目标遗传算法/用法不用多说、要用的赶快下载吧」· M 代码 · 共 43 行

M
43
字号
function g = set(gen,varargin)% SET - This function gives acces to the fields in the gene. % Any number of valid properties can be set with one function% call.  The syntax for calling the function is:% set(gene,'property',value,'property',value,etc..).  The% properties are:%% 'name' - the name of the variable% 'value' - the value of the variable% 'bits' - number of coding bits% 'dna' - a vector containing the binary "dna"% 'l_limit' - the lower limit for a cdv% 'u_limit' - the upper limit for a cdv% 'p_val' - the possible values for a ddv [val1 val2 etc...]%% to list the valid properties for a certain object use set(gene)tst=nargin;if tst==1  fprintf('Valid properties:\nname \nvalue \nbits\ndna\n')  else  if ~or(or(tst==3,tst==5),tst==7)    error('wrong number of arguments')  else    for k=1:2:tst-1      switch varargin{k}       case 'name'	gen.name=varargin{k+1};       case 'value'	gen.value=varargin{k+1};       case 'bits'	gen.bits=varargin{k+1};       case 'dna'	gen.dna=varargin{k+1};     otherwise      error('Unknown method')      end    end    g=gen;  endend

⌨️ 快捷键说明

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