Help! S-Function error message: "Output returned by S-function 'Hi_plant_sfcn' in 'untitled/S-Function' during flag=3 call must be a real vector of length 1"

14 visualizzazioni (ultimi 30 giorni)
S-Function brings the following error message:
"Output returned by S-function 'Hi_plant_sfcn' in 'untitled/S-Function' during flag=3 call must be a real vector of length 1"
my code:
function [sys,x0,str,ts] = sfcn(t,x,u,flag)
%{
Despacha a bandeira. A função de troca controla as chamadas para
rotinas da S-Function em cada estágio de simulação.
%}
A = [-72 -8100;1 0];
B = [1;0];
C = [0 2.4e8];
D = 0;
switch flag,
case 0
[sys,x0,str,ts] = mdlInitializeSizes(A,B,C,D); % Inicialização
case 1,
%Calcula as derivadas do estado de variáveis contínuas
sys=mdlDerivatives(t,x,u,A,B)
case 3
sys = mdlOutputs(t,x,u,C,D); % Calculo das saídas
case {2, 4, 9 } % Sinalizações não usadas
% 2:discrete
% 4:calctimeHit
% 9:termination
sys = [];
otherwise
error(['Unhandled flag = ',num2str(flag)]); % Error handling
end;
function [sys,x0,str,ts]=mdlInitializeSizes(A,B,C,D)
str=[]; % Sem ordenação de estado
ts = [0 0]; % Tempo de amostra herdado
s = simsizes;
s.NumContStates= length(A); % Número de estados continuos
s.NumDiscStates= 0; % Número de estados discretos
s.NumOutputs= 1; % Número de saídas
s.NumInputs= 1; % Número de entradas
s.DirFeedthrough= 0; % Sinalizar para feedthrough direto
s.NumSampleTimes= 1; % Número de amostras de tempo
sys = simsizes(s);
x0 = [0 0];
function sys=mdlDerivatives(t,x,u,A,B)
sys = A*x + B*u;
function sys=mdlOutputs(t,x,u,C,D)
sys = C*x + D*u;
S-Function on Simulink:
If anyone can help me understand what's wrong with this code, I appreciate it.

Risposte (0)

Categorie

Scopri di più su Modeling in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by