Simulink does not support code generation issue.
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to replace a 3-point summing block with a function block.
First I started by placing the code inside the function block:
function y = fcn(u)
sys1 = tf(0.5,[1 0 0 4]);
sys2 = tf([3 0.5],[1 0 15]);
sys3 = tf(1,[1 1]);
y = sys1 + sys2 + sys3;
However I was greeted with an error saying that Simulink does not support code generation.
"The 'tf' class does not support code generation."
I then came across a similar problem here: https://nl.mathworks.com/matlabcentral/answers/74770-is-there-any-way-to-disable-code-generation-in-simulink
I am trying to implement an extrinsic function or'wrapper function` with some difficulty. I created a new script called myWrapper.m, containing the same code:
function y = myWrapper(u)
sys1 = tf(0.5,[1 0 0 0 4]);
sys2 = tf([3 5],[1 0 15]);
sys3 = tf(1,[1 1]);
y = sys1 + sys2 + sys3;
and the MATLAB Function edited to:
function y1 = fcn(u1)
y1 = myWrapper(u1);
The error persists.
I somehow want to access `myWrapper.m` file from the MATLAB Function block. Any pointers on how this should be done? Following the previous link given and the [official docs][2] I am ending up with something like this in my MATLAB Function block:
function y = fcn(u)coder.extrinsic('myWrapper')
y = myWrapper(u);
The last code above is syntactically incorrect and I am at a loss on how it should be done. MATLAB automaticaly corrects the above code to:
function y = fcn(u,coder,extrinsic, myWrapper )
y = myWrapper(u);
which is not what I want.
Any tips on how this could be done would be appreciated.
0 commentaires
Réponses (1)
Saurabh
le 31 Juil 2024
Hi Ryan,
According to my assumption, you want to replace the 3-point ‘Sum Block’ and ‘Transfer function’ block with the ‘MATLAB function block ’, and you are using the ‘tf’ function to replicate the work of the transfer function block and while code generation you are encountering an error that ‘The tf class does not support code generation’
I tried it on my end and found that to replace the ‘sum’ block, one must not remove the 'transfer function' blocks which feed into the summing block.
You cannot generate code for classes that inherit from built-in MATLAB classes.
You can find this information on the provided link:
A workaround would be to simply feed into the MATLAB Function from all the Transfer function block.
The above picture is the demo description what I want to Implement.
Thescript would simply be:
function y = fcn(u, data, data1)
y = (u1 + data +data1);
end
I hope this was helpful.
0 commentaires
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!