Filter löschen
Filter löschen

how to fix MATLAB Function block issue?

4 Ansichten (letzte 30 Tage)
zubair younas
zubair younas am 8 Apr. 2019
Kommentiert: madhan ravi am 9 Apr. 2019
i am using MATLAB Function for my model as a relay such as
function y = fcn(P,T)
if(T <= 12.0)
y=1;
else
if (P <= 4800000)
y=0;
else
y=1;
end
end
and this is working well
but i have to find mean value of 5 maximum peaks in a specific interval
so i am writing my code such as
function y = fcn(P,T)
if(T <= 12.0)
y=1;
else
if ((mean(maxk(findpeaks(P((T >= 12) & (T <= 12.1))),5))) <= 4800000)
y=0;
else
y=1;
end
end
but matlab function block giving error where as this command {(mean(maxk(findpeaks(P((T >= 12) & (T <= 12.1))),5)))} is working in command window but showing error when i use it in Matlab function block
following error comes
Function 'maxk' is not supported for code generation. Consider adding coder.extrinsic('maxk') at the top of the function to bypass code generation

Antworten (1)

Raj
Raj am 9 Apr. 2019
Your question itself is self explanatory and the error message is the solution to your problem. Many inbuilt MATLAB functions like the one you are using (maxk) are not supported for code generation. If you are using there functions in your model, you will have to declare them as "coder.extrinsic". It basically means that "During simulation, the code generator produces code for the call to an extrinsic function, but does not produce the function's internal code. Therefore, simulation can run only on platforms where MATLAB software is installed. During standalone code generation, MATLAB attempts to determine whether the extrinsic function affects the output of the function in which it is called. Provided that there is no change to the output, MATLAB proceeds with code generation, but excludes the extrinsic function from the generated code. Otherwise, compilation errors occur."
See full details here
Now that being said, if you want to generate code for the full function then you will have to remove coder.extrinsic MATLAB functions from your model and use self defined functions that basically do the same job.

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by