www.pudn.com > CR_simulink.rar > dfs.m, change:2006-10-23,size:1414b


 
function [sys, x0, str, ts] = dfs(t, x, u, flag) 
 
switch flag, 
    case 0  
        [sys,x0, str, ts] = mdlInitializeSizes; 
    case 3 
        sys = mdlOutputs(t,x,u); 
    case {1,2,4,9} 
        sys = []; 
    otherwise 
        error(['Unhandled flag = ', num2str(flag)]); 
                 
end; 
 
function [sys, x0, str, ts] = mdlInitializeSizes 
sizes = simsizes; 
sizes.NumContStates = 0; 
sizes.NumDiscStates = 0; 
sizes.NumOutputs = 1; 
sizes.NumInputs = 1000; 
sizes.DirFeedthrough = 1; 
sizes.NumSampleTimes = 1; 
sys = simsizes(sizes); 
x0=[]; 
str=[]; 
ts=[-1,0]; 
function sys = mdlOutputs(t,x,u) 
for i=501+200:501+280 
    sel = 1; 
    if u(i) < 0.2 
        if i < 10+200+501 
            for j=200+501:i+10 
                if u(j) > 0.2 
                    sel = 0; 
                    break; 
                end                 
            end 
        elseif i+10 >= 10+200+501 && i+10 < 280+501 
            for j=i-10:i+10 
                if u(j) > 0.2 
                    sel = 0; 
                    break; 
                end 
            end 
        else 
            for j=i-10:280+501 
                if u(j) > 0.2 
                    sel = 0; 
                    break; 
                end 
            end 
        end 
        if sel == 1 
            i 
            sys = i; 
            break; 
        end 
    end 
end 
 
if sel == 0 
    sys = 0; 
end