MATLAB Fcn not yet supported by Simulink coder

3 visualizzazioni (ultimi 30 giorni)
Shuyi shao
Shuyi shao il 20 Nov 2017
Commentato: Walter Roberson il 21 Nov 2017
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 Commenti
Nicolas Schmit
Nicolas Schmit il 20 Nov 2017
Please post the complete error message.
Shuyi shao
Shuyi shao il 20 Nov 2017
Modificato: Walter Roberson il 20 Nov 2017
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

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 20 Nov 2017
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 Commenti
Shuyi shao
Shuyi shao il 21 Nov 2017
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 il 21 Nov 2017
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

Accedi per commentare.

Categorie

Scopri di più su 执行速度 in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!