www.pudn.com > communicationmatlab.rar > ARRAYMAX.M


function [sys, x0, str, ts] = arraymax(t,x,u,flag) 
%ARRAYmax outputs the index of the maximum input. 
%       This M-file is designed to be used in a SIMULINK S-function block. 
%       This function will detecte the maximum number from the input and  
%       output the index number where the maximum number occured. 
 
%       Wes Wang 4/13 
%       Copyright (c) 1995-96 by The MathWorks, Inc. 
 
if flag == 3 
    sys = find(u==max(u)); 
    sys = sys(1) - 1;     
elseif flag == 0 
    sys=zeros(7,1); 
    %one sample rate 
    sys(7) = 1; 
    sys(4) = -1; 
    sys(3) = 1; 
    x0 = []; 
    ts = [-1. 0]; 
else 
    sys = []; 
end;