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

📄 wtrandperm.m

📁 物流分析工具包。Facility location: Continuous minisum facility location, alternate location-allocation (ALA)
💻 M
字号:
function idx = wtrandperm(w,nin)
%WTRANDPERM Weighted random permutation.
%   idx = wtrandperm(w,n)
%     w = p-element vector of weights
%     n = length of output value (faster to use n if only first n elements
%         of idx are needed and n < length of w)
%       = length of w, default
%   idx = n-element permutation vector, where the probability that
%         idx(1) == i is w(i)/sum(w)
%
% See also RANDPERM and WTROUSELECT

% Copyright (c) 1994-2006 by Michael G. Kay
% Matlog Version 9 13-Jan-2006 (http://www.ie.ncsu.edu/kay/matlog)

% Input Error Checking ****************************************************
error(nargchk(1,2,nargin));

if nargin < 2 || isempty(nin), nin = length(w(:)); end

if min(size(w)) ~= 1
   error('"w" must be a vector.')
end
% End (Input Error Checking) **********************************************

idxw = 1:length(w);

idxw0 = find(is0(w(:)'));  % Remove 0 elements of w and put at end of idx
idxw(idxw0) = [];
n = min(nin,length(w(:)) - length(idxw0));

idx = zeros(1,n);
for i = 1:n
   idxi = wtrouselect(w(idxw));
   idx(i) = idxw(idxi);
   idxw(idxi) = [];
end

idx = [idx idxw0];
idx = idx(1:nin);

if size(w,2) == 1, idx = idx'; end

⌨️ 快捷键说明

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