fairmax.m

来自「最优潮流计算应用matlab程序计算最优潮流问题。包括14节点等。」· M 代码 · 共 21 行

M
21
字号
function [val, idx] = fairmax(x)%FAIRMAX    Same as built-in max(), except breaks ties randomly.%   [val, idx] = fairmax(x) takes a vector as an argument and returns%   the same output as the built-in function max (see 'help max' for details.)%   with two output parameters, except that where the maximum value occurs%   at more than one position in the  vector, the index is chosen randomly%   from these positions as opposed to just choosing the first occurance.%   MATPOWER%   $Id: fairmax.m,v 1.3 2004/08/23 20:56:17 ray Exp $%   by Ray Zimmerman, PSERC Cornell%   Copyright (c) 1996-2004 by Power System Engineering Research Center (PSERC)%   See http://www.pserc.cornell.edu/matpower/ for more info.val = max(x);               %% find max valuei   = find(x == val);       %% find all positions where this occursn   = length(i);            %% number of occurencesidx = i( fix(n*rand)+1 );   %% select index randomly among occurancesreturn;

⌨️ 快捷键说明

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