Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
How can I implement a MATLAB code into an Embedded MATLAB block in Simulink?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello guys,
Below you can see a Matlab code I need to implement in Simulink using the embedded function block. I tried to rewrite the code so it could be used in the function block, but the results have some differences. Any suggestions?
Thanks.
% code
|*MATLAB CODE*
load('P.mat')
a=35;
X1(1,1)=0;
t=5;
k=1;
while k<3601
X1(k+1,1)=(1-1/a)*X1(k,1)+1/a*(-P(k,1));
if X1(k+1,1)>=0&&X1(k,1)<0||X1(k+1,1)<=0&&X1(k,1)>0
dx=(X1(k+1,1)-X1(k,1))/(t);
K=1;
while K<=t
X1(k+1,1)=X1(k,1)+dx;
K=K+1;
k=k+1;
end
end
end
*MATLAB function BLOCK*
function X1 = fcn(P)
persistent S1
if isempty(S1)
S1 = 0;
end
X=S1;
a=35;
t=5;
X1=(1-1/a)*X+1/a*P;
if X1>=0&&X<0||X1<=0&&X>0
dx=(X1-X)/t;
for K=1:t
X1=X+dx;
end
end
S1=X1;|
0 comentarios
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!