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

📄 nullexceeding.m

📁 The Source of Genetic Programming developed in Matlab
💻 M
字号:
function y=nullexceeding(x,n)
%NULLEXCEEDING    Nulls numbers in list so that sum does not exceed limit.
%   NULLEXCEEDING(LIST,LIMIT) returns LIST with null values in all elements
%   that would cause list sum to exceed LIMIT. Elements are accepted (number
%   maintained) or rejected (number nulled) by their order in LIST. 
%   
%   Input arguments:
%      LIST - list of integers representing sizes of individuals (array)
%      LIMIT - maximum number of nodes (sum of sizes) to pick in LIST (integer)
%   Output arguments:
%      NEWLIST - same as LIST but with null values in rejected elements (array)
%
%   Example:
%      LIST=[20,18,31,4,30,12,20,10,3,3,1,5]
%      LIMIT=100
%      NEWLIST=NULLEXCEEDING(LIST,LIMIT)
%      NEWLIST=[20,18,31,4,0,12,0,10,3,0,1,0]
%
%   Copyright (C) 2003-2007 Sara Silva (sara@dei.uc.pt)
%   This file is part of the GPLAB Toolbox

cumx=cumsum(x);
while sum(cumx>n)>0
   goodcumx=cumx(find(cumx<=n));
   if ~isempty(goodcumx)
     lastgood=goodcumx(end);
   else
     lastgood=0;
   end
   x(find(cumx>n & x+lastgood>n))=0;
   cumx=cumsum(x);
end
y=x;

⌨️ 快捷键说明

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