Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

ekf matlab switch flag error

2 visualizaciones (últimos 30 días)
abbas ogur
abbas ogur el 24 de Jun. de 2017
Cerrada: Sabin el 20 de Jun. de 2025
hello every body i have to build an ekf model for PMSM motor so searched and found this code
function [sys,x0,str,ts]=EKM6a(t,x,u,flag,P,Q,R);
%global Rs Ld Lq Fm v_alpha v_beta i_alpha i_beta;
%global P Q R fid;
%global out fit;
Rs=5;
Ld=10e-3;
Lq=10e-3;
Fm=0.175;
T=5e-4;
%i=0;
Bd=[1/Ld 0;0 1/Lq;0 0;0 0];
H=[1 0 0 0;0 1 0 0];
switch flag
case 0
%ekmini;
sizes=simsizes;
sizes.NumContStates=0;
sizes.NumDiscStates=4;
sizes.NumOutputs=4;
sizes.NumInputs=4;
sizes.DirFeedthrough=0;
sizes.NumSampleTimes=1;
str=[];
ts=[0.0005 0];
x0=[0; 0; 0; 0];
sys = simsizes(sizes);
case 2
% Step 1:Initialization of the state vector and covariance matrices
Uk=[u(1);u(2)];
Y=[u(3);u(4)];
% Step 2:Prediction of the state vector
fx=[-Rs/Ld*x(1)+Fm/Ld*x(3)*sin(x(4)) ;-Rs/Lq*x(2)-Fm/Lq*x(3)*cos(x(4)) ;0 ;x(3) ];
F=[-Rs/Ld 0 Fm/Ld*sin(x(4)) Fm/Ld*x(3)*cos(x(4));0 -Rs/Lq -Fm/Lq*cos(x(4)) Fm/Lq*x(3)*sin(x(4));0 0 0 0;0 0 1 0];
x1=x+T*(fx+Bd*Uk);
% Step 3: Covariance estimation of prediction
P1=P+T*(F*P+P*F')+Q; % P1 is 4x4
% Step 4: Kalman filter gain computation
K1=P1*H'*inv(H*P1*H'+R);% K1 is 4x2
% Step 5: State vector estimation
h=[x1(1);x1(2)];
sys=x1+K1*(Y-h);
% Step 6: Covariance matrix of estimation error
P=P1-K1*H*P1;
case 3
sys=x;
case 4
sys=(round(t/T)+1)*T;
%sys=[];
case 9
sys=[];
end
if true
% code
end
the problem is when i run the code it's gave me the error below:
EKM6a
Not enough input arguments.
Error in EKM6a (line 14)
switch flag
i dont know how to solve this problem please help me
  2 comentarios
Ge Zhang
Ge Zhang el 5 de Dic. de 2022
I have the same 'Not enough input' problem, did you find the way to fix it?
jessupj
jessupj el 5 de Dic. de 2022
you don't run the code. it's a function, so you have to CALL the function by passing it arguments.

Respuestas (0)

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by