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 个评论
回答(1 个)
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 个评论
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!