get.m

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

M
48
字号
function varargout =get(gen,varargin)% GET - Returns the values of the design variable corresponding to% the property list. Any number of properties can be returned with one% function call. %   % [val1 val2 etc...]=get(gene,'property','property',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 get(gene)tst=nargin;if tst==1  fprintf('Valid properties:\nname \nvalue \nbits\ndna\n')else  if ~or(or(tst==2,tst==3),tst==4)    error('bad number of arguments')  end  for k=1:tst-1    switch varargin{k}   case 'name'    varargout{k}=gen.name;     case 'value'      varargout{k}=gen.value;     case 'bits'      varargout{k}=gen.bits;     case 'dna'    varargout{k}=gen.dna;     otherwise      txt=strcat('bad argument:',varargin{k});      error(txt)    end  endend

⌨️ 快捷键说明

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