MATLAB Fcn not yet supported by Simulink coder

3 次查看(过去 30 天)
I am using "MATLAB Fcn " module in Simulink. But when I am trying to build my code it gives me an error message that ""MATLAB Fcn" is not yet supported by Simulink Coder". The code is given as follows:
function yd=roll(rollangr,vd,t)
persistent N1;
x2=rollangr;
e2=x2-vd;
N1=[N1;e2];
But the code N1=[N1;e2]; is impassability. Can you guide me how to fix this error. Thank you very much.
  2 个评论
Shuyi shao
Shuyi shao 2017-11-20
编辑:Walter Roberson 2017-11-20
Thank you very much.
The error message is "Undefined function or variable 'N1'. The first assignment to a local variable determines its class."
If I use "Interpreted MATLAB Fcn " module in Simulink, the code is correct. Since the restriction of simulation environment, I must use "MATLAB Fcn " module in Simulink.
the complete code as follows:
function yd=roll(rollangr,vd,t)
persistent N1;
x2=rollangr;
e2=x2-vd;
N1=[N1;e2];
a=((t*1000)/2)+1;
beta=0.001;
F1=0;
if a<=160
for i=1:a
f=1;
for k1=1:a
f=(beta-(k1+1)+1)*f;
end
k2=k1+1;
f=(-1)^(k2)*(f/(prod(1:k2)));
F1=f*N1(i)+F1;
end
else
a=160; F1=0;
for i=1:a
f=1;
for k1=1:a
f=(beta-(k1+1)+1)*f;
end
k2=k1+1;
f=(-1)^(k2)*(f/(prod(1:k2)));
F1=f*N1(i)+F1;
end
end
yd=F1;
end

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2017-11-20
Your N1 is going to get larger every time roll() is called, by a size that is not obvious in the code 9since your inputs might be vectors or arrays.)
Simulink does not allow variables to grow to indefinite size in code generation, at least not without you having specifically turned on dynamic memory allocation for the variable.
If you need that variable to keep growing, then you should be using coder.varsize to signal the size, and you should probably be taking steps to place a maximum size on the variable, such as
if size(N1, 1) >= 200
N1(1:199,:) = N1(end-199:end,:);
N1(200,:) = e2;
N1(201:end,:) = [];
else
N1(end+1,:) = e2;
end
On the other hand, as you are not using N1 for further computation, and since your function has no way to output N1, why are you bothering to set N1 at all?
  11 个评论
Shuyi shao
Shuyi shao 2017-11-21
I am sorry to disturb you. The above problem has been settled. However, there is still sa mistake. The error message "persistent variable 'N1' is undefined on some execution paths". The corresponding code is "N1(a) = e2;" Can you guide me how to fix this error. Thank you very much.
The complete code as follows:
function yd=rollSUMWUC(rollangr,vd,t)
persistent N1;
x2=rollangr;
e2=x2-vd;
beta=0.001;
F1=0;
a=((t*1000)/2)+1;
if a == 1
N1 = zeros(160,1);
end
if a <= 160
N1(a) = e2;
end
if a<=160
for i=1:a
f=1;
for k1=1:a
f=(beta-(k1+1)+1)*f;
end
k2=a+1;
f=(-1)^(k2)*(f/(factorial(k2)));
F1=f*N1(i)+F1;
end
else
a=160; F1=0;
for i=1:a
f=1;
for k1=1:a
f=(beta-(k1+1)+1)*f;
end
k2=a+1;
f=(-1)^(k2)*(f/(factorial(k2)));
F1=f*N1(i)+F1;
end
end
yd=F1;
end
Walter Roberson
Walter Roberson 2017-11-21
I am not sure. You could try changing
if a == 1
N1 = zeros(160,1);
end
to
if isempty(N1)
N1 = zeros(160,1);
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 执行速度 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!