?? fairmax.m
字號:
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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -