Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can I implement a MATLAB code into an Embedded MATLAB block in Simulink?

1 回表示 (過去 30 日間)
Juan Nunez
Juan Nunez 2018 年 10 月 31 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by