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

📄 set.m

📁 一些用matlab编写的经典遗传算法算例 挺有用的
💻 M
字号:
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;
  end
end

⌨️ 快捷键说明

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