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

📄 load_chrom.m

📁 一些用matlab编写的经典遗传算法算例 挺有用的
💻 M
字号:
function chr = load_chrom(fname,varargin)
% LOAD_CHROM - Loads a chromosome vector.
%
%   c = load_chrom('fname',opt), loads a chromosome vector (generation)
%   from a file. The opt is a options is the generation to beloaded
%   or 'all', all the generations.  In the last case chr is a nxm
%   matrix with the n generations and m chromosomes.


fid=fopen(fname,'r');
gen=fgetl(fid);
gen=str2num(gen(20:end));

if ~isempty(varargin)
  if isa(varargin{1},'double')
    if varargin{1}<=gen
      gen=varargin{1};
    end
  elseif isa(varargin{1},'char')
    if strcmp(varargin{1},'all')
      ind=1;
      while ~feof(fid)
	chr(ind,:)=cload(fid);
	ind=ind+1;
      end
      fclose(fid);
    end
    return
  else 
    error('wrong argument')
  end
  
end


gen_load=sprintf('Generation %g',gen);
tst='';
while ~strcmp(tst,gen_load )
  b=ftell(fid);
  tst=fgetl(fid);
  ind=findstr(tst,'saved');
  if ind
    tst=tst(1:ind-2);
    if strcmp(tst,gen_load)
      fseek(fid,b,-1);
      chr=cload(fid);
      fclose(fid);
      break
    end
  end
  
  if strcmp(tst,'-1');
    fclose
    error('generation not found')
    break
  end
  
end
  



⌨️ 快捷键说明

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