s-function error ,flag = 3 (output), at time 0.0.
    조회 수: 11 (최근 30일)
  
       이전 댓글 표시
    
Hello, I have problem with my s-function
    Error in 'Celanovic_3niv2/Nearest three vectors/S-Function' while executing MATLAB S-function 'Celanovic', flag = 3 (output), at time 0.0.
And this is my s-function:
   function [sys,x0,str,ts] = Celanovic(t,x,u,flag)
    %Este comentario saldra en matlab cuando le demos a help
    %VSI_2L_hysteresis_v0. Lo normal es poner aqui una explicacion de lo que
    %hace este bloque
    switch flag,
      %%%%%%%%%%%%%%%%%%
      % Initialization %
      %%%%%%%%%%%%%%%%%%
      % Initialize the states, sample times, and state ordering strings.
      case 0
        [sys,x0,str,ts]=mdlInitializeSizes;
      %%%%%%%%%%%
      % Outputs %
      %%%%%%%%%%%   
      % Return the outputs of the S-function block.
      case 3
        sys=mdlOutputs(t,x,u);
      %%%%%%%%%%%%%%%%%%%
      % Unhandled flags %
      %%%%%%%%%%%%%%%%%%%
      % There are no termination tasks (flag=9) to be handled.
      % Also, there are no continuous or discrete states,
      % so flags 1,2, and 4 are not used, so return an emptyu
      % matrix 
      case { 1, 2, 4, 9 }
        sys=[];
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      % Unexpected flags (error handling)%
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      % Return an error message for unhandled flag values.
      otherwise
        error(['Unhandled flag = ',num2str(flag)]);
    end
    % end timestwo
    %
    %=============================================================================
    % mdlInitializeSizes
    % Return the sizes, initial conditions, and sample times for the S-function.
    %=============================================================================
    %
    function [sys,x0,str,ts] = mdlInitializeSizes()
    sizes = simsizes;
    sizes.NumContStates  = 0;
    sizes.NumDiscStates  = 0;
    sizes.NumOutputs     = 12;  %%%DEFINIR AQUI EL NUMERO DE SALIDAS DEL BLOQUE
    sizes.NumInputs      = 2;  %%%DEFINIR AQUI EL NUMERO DE ENTRADAS DEL BLOQUE
    sizes.DirFeedthrough = 1;   % has direct feedthrough
    sizes.NumSampleTimes = 1;
    %global tm;
    sys = simsizes(sizes);
    str = [];
    x0  = [];
    ts  = [-1 0];   % inherited sample time
    %ts  = [tm 0];   % inherited sample time
    % end mdlInitializeSizes
    %
    %=============================================================================
    % mdlOutputs
    % Return the output vector for the S-function
    %=============================================================================
    %
    function sys = mdlOutputs(t,x,u)
    %Aqui se muestrean los valores de las señales de entrada
    Vrefg=u(1);
    Vrefh=u(2);
    Vsw1=0;
    Vsw=0;
    Ts=200;
    Vdc=120;
    Vrefgmax=sqrt(2)*2*Vdc*cos(pi/6);
    R1=0;
    R2=0;
    R3=0;
    global V1g
    global V1h
    global V2g
    global V2h
    global V3g
    global V3h
    global d1
    global d2
    global d3
    global contador 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%Aqui hay que escribir la rutina de control de corriente por histéresis
       if (contador>=Ts)
        contador=0;    
        %#Determinacion vectores mas cercanos    
        Vul=[ceil(Vrefg); floor(Vrefh)];
        Vlu=[floor(Vrefg); ceil(Vrefh)];
        Vuu=[ceil(Vrefg); ceil(Vrefh)];
        Vll=[floor(Vrefg); floor(Vrefh)];
        %Calculo tercera tension y tiempos de disparo
        if Vrefg+Vrefh-(Vul(1,:)+Vul(2,:))>0
            V3=Vuu;
            dul=-(Vrefh-Vuu(2,:));
            dlu=-(Vrefg-Vuu(1,:));
            duu=1-dul-dlu;
            d3=duu;
            else
            V3=Vll;
            dul=Vrefg-Vll(1,:);
            dlu=Vrefh-Vll(2,:);
            dll=1-dul-dlu;  
            d3=dll;
        end
        V1g=Vul(1,:)
        V1h=Vul(2,:)
        V2g=Vlu(1,:)
        V2h=Vlu(2,:)
        V3g=V3(1,:)
        V3h=V3(2,:)
        d1=dul
        d2=dlu
        d3
            %Calculo estados inverter a travès de las tensiones V1,V2,V3
        g=V1g;
        h=V1h;
        k=0:1:2; 
        Vsw1=[k; k-g; k-g-h]';
        logicalArray = ~(Vsw1 >= 0 & Vsw1 <= 2);
        rowsToKeep = sum(logicalArray, 2) == 0;
        Vsw2 = Vsw1(rowsToKeep,:);
        Vsw=Vsw2(1,:);
        R1=Vsw(:,1);
        R2=Vsw(:,2);
        R3=Vsw(:,3);
    else
        contador=contador+1;
        if contador>(d1+d2)*Ts 
            g=V3g;
            h=V3h;
            k=0:1:2; 
            Vsw1=[k; k-g; k-g-h]';
            logicalArray = ~(Vsw1 >= 0 & Vsw1 <= 2);
            rowsToKeep = sum(logicalArray, 2) == 0;
            Vsw2 = Vsw1(rowsToKeep,:);
            Vsw=Vsw2(1,:)  
            R1=Vsw(:,1);
            R2=Vsw(:,2);
            R3=Vsw(:,3);
        elseif contador>d1*Ts
                g=V2g;
                h=V2h;
                k=0:1:2; 
                Vsw1=[k; k-g; k-g-h]';
                logicalArray = ~(Vsw1 >= 0 & Vsw1 <= 2);
                rowsToKeep = sum(logicalArray, 2) == 0;
                Vsw2 = Vsw1(rowsToKeep,:);
                Vsw=Vsw2(1,:)      
                R1=Vsw(:,1);
                R2=Vsw(:,2);
                R3=Vsw(:,3);
            else
                g=V1g;
                h=V1h;
                k=0:1:2; 
                Vsw1=[k; k-g; k-g-h]';
                logicalArray = ~(Vsw1 >= 0 & Vsw1 <= 2);
                rowsToKeep = sum(logicalArray, 2) == 0;
                Vsw2 = Vsw1(rowsToKeep,:);
                Vsw=Vsw2(1,:)
                R1=Vsw(:,1);
                R2=Vsw(:,2);
                R3=Vsw(:,3); 
            end
        end  
        %#Disparo IGBT 
    if R1==0
               Igbt1=0;  
               Igbt2=0;           
               Igbt3=1;  
               Igbt4=1;
    elseif R1==1
               Igbt1=0; 
               Igbt2=1;
               Igbt3=1;
               Igbt4=0; 
    elseif R1==2
               Igbt1=1;
               Igbt2=1;
               Igbt3=0;  
               Igbt4=0;
    end
    if R2==0
               Igbt5=0;
               Igbt6=0;   
               Igbt7=1;
               Igbt8=1;
    elseif R2==1
               Igbt5=0;
               Igbt6=1;
               Igbt7=1;
               Igbt8=0;
        elseif R2==2
               Igbt5=1;
               Igbt6=1;
               Igbt7=0;
               Igbt8=0;
    end
    if R3==0
               Igbt9=0;
               Igbt10=0;
               Igbt11=1;
               Igbt12=1;
    elseif R3==1
               Igbt9=0;
               Igbt10=1;
               Igbt11=1;
               Igbt12=0;
    elseif R3==2
               Igbt9=1;
               Igbt10=1;
               Igbt11=0;
               Igbt12=0;
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % En el vector sal se guardan los valores de salida que serán los disparos
    % de los transistores y aquellas variables auxiliares que nos interese
    % visualizar en simulink
    sal(1)=Igbt1;
    sal(2)=Igbt2;
    sal(3)=Igbt3;
    sal(4)=Igbt4;
    sal(5)=Igbt5;
    sal(6)=Igbt6;
    sal(7)=Igbt7;
    sal(8)=Igbt8;
    sal(9)=Igbt9;
    sal(10)=Igbt10;
    sal(11)=Igbt11;
    sal(12)=Igbt12;
    sys = sal;
    % end mdlOutputs
Could you please help me with my problem.
댓글 수: 1
  Kaustubha Govind
    
      
 2014년 6월 27일
				You didn't specify the error message, but I would recommend setting breakpoints in your code to understand the issue better.
답변 (1개)
  Thomas Apelt
 2015년 3월 11일
        I had a similar error:
 An error occurred while running the simulation and the simulation was terminated
Error in 'circ1_2015/Ball Mill/Product Calculation/Product S-Func (tph by size)' while executing MATLAB S-function 'BM_Prod_2015', flag = 3 (output), at time 0.0.
Data points in complex number format are not supported. Use REAL and IMAG to extract the real and imaginary components. Component: Simulink | Category: Block error
--------------
I'm still trouble shooting it. The S-function code and model file were originally Matlab 11. Upgrade was completed successfully with all checks green and good to go. It still could be an upgrade issue...
댓글 수: 1
참고 항목
카테고리
				Help Center 및 File Exchange에서 Switches and Breakers에 대해 자세히 알아보기
			
	제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



