Matlab Simulink S-function

Fermé
guigs22 - 5 juin 2013 à 14:39
Bonjour,

Voici une partie du programme que j'ai écris :
(je rentre avec un vecteur [1 0 1])


function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes

%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded.  This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;

sizes.NumContStates  = 6;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 3;
sizes.NumInputs      = 3;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;   % at least one sample time is needed

sys = simsizes(sizes);

%
% initialize the initial conditions
%
x0  = [0 0 10 0 0 0];

%
% str is always an empty matrix
%
str = [];

%
% initialize the array of sample times
%
ts  = [0 0];



% end mdlInitializeSizes

%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%   
function sys=mdlDerivatives(t,x,u)

M = [cos(x(6)) sin(x(4))*sin(x(6)) 0;-sin(x(6)) sin(x(4))*cos(x(6)) 0;0 cos(x(4)) 1]
Y=[x(1);x(2);x(3)]
sys=[x(4:6) ; inv(M)*Y]


% end mdlDerivatives

%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)


sys = [];

% end mdlUpdate

%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)

sys = x(4:6);

% end mdlOutputs


Et au final, j'ai cette erreur :

State derivatives returned by S-function 'matrix' in 'sat/S-Function2' during flag=1 call must be a real vector of length 6


Et je n'arrive pas à la résoudre mais ça vient du inv(M) je pense :/
Merci d'avance pour votre aide.