MATLAB: How to correct the following error:The extrinsic function ‘ ‘ is not available for standalone code generation It must be eliminated for stand-alone code to be generated….

code generationCurve Fitting ToolboxfunctionMATLABmatlab functionplc codersimulinksimulink coderSimulink PLC Coder

I have a MATLAB function block in Simulink and I'm using it to generate a spline function but every time I try to generate a code using PLC Coder out of it, I keep getting this error:
The extrinsic function 'function_trial' is not available for standalone code generation. It must be eliminated for stand-alone code to be generated. It could not be eliminated because its outputs appear to influence the calling function. Fix this error by not using 'function_trial' or by ensuring that its outputs are unused.
and i tried to put all my code in one function but it didn't work.
here is my code:
%

function y2 = function_trial(points,w)
r2=(([0:2:360]/180)*pi);
points=sin(r2);
m=[r2' points'];
t = (0:180);
points = m;
x=points(:,1);
y=points(:,2);
tq = 0:0.1:180;
slope0 = 0;
slopeF = 0;
xq = spline(t,[slope0; x; slopeF],tq);
yq = spline(t,[slope0; y; slopeF],tq);
values = csaps( xq, yq);
y2=fnval(values, w);
main block function:
%
function out = fcn(points, w)
coder.extrinsic('function_trial');
out=0;
out=function_trial(points , w);
any Idea how can I solve this issue?
Thank you!

Best Answer

I've achieved my goal by building a curve between 3 points and finding out the value of an ordinate on it. I wrote a function in the "Matlab function" simulink block and it works!

code:

 %
function position = fcn(angle,  point)
x = (0:2:358);
index=(angle/2)+1;
index1 = floor(index);
    if any(index1<2)
        index2=index1+1;
        index3=index1+2;
        index4=index1+3;
    elseif any(index1>177)
        index2=index1-1;
        index3=index1-2;
        index4=index1-3;
    else
        index2=index1+1;
        index3=index1-1;
        index4=index1+2;
    end
y=[point(index1); point(index2); point(index3); point(index4)];
M=[x(index1).^3 x(index1).^2 x(index1) 1;x(index2).^3 x(index2).^2 x(index2) 1;x(index3).^3 x(index3).^2 x(index3) 1;x(index4).^3 x(index4).^2 x(index4) 1];
M_inverse= inv(M);
q=(M_inverse)*(y);
a=q(1);
b=q(2);
c=q(3);
d=q(4);
position=(a*angle.^3)+(b*angle.^2)+(c*angle)+d ;