How to bring in pre-built or pre-made functions from MATLAB to Simulink without rewriting them into new "MATLAB function" blocks?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jonathan Bessette
le 7 Mai 2023
Commenté : Jonathan Bessette
le 7 Mai 2023
Hey folks, say I have a function in MATLAB that I wrote
for example: "add_two_numbers.m" which I attached,
And I want to place it in Simulink as a block (in this simplified example case, [x,y] input and [z] output) in a model, e.g., "Model.slx".
I see that "MATLAB Function" exists in Simulink (see attached image), however, I don't want to have to copy and paste every new function I make and save it as a new function block in Simulink. To elaborate, this information https://www.mathworks.com/help/simulink/slref/matlabfunction.html is unsatisfying because they write an entirely new function in the block, rather than referencing something they've already edited and created.
This may be an obvious question that I missed in documentation, but is there any way to directly call in Simulink, a function I previously made in MATLAB? I wish I could just drag and drop the function from my path and have it pop up in Simulink. I'd love to be able to edit the function in MATLAB's editor and then use it in Simulink, and have this function in Simulink auto-update / be linked to the MATLAB function.
Let me know! Thanks so much,
Jon
0 commentaires
Réponse acceptée
Walter Roberson
le 7 Mai 2023
is there any way to directly call in Simulink, a function I previously made in MATLAB?
No, not as far as I can tell.
You can write Level 2 S functions in MATLAB, https://www.mathworks.com/help/simulink/sfg/writing-level-2-matlab-s-functions.html but that is non-trivial work.
Sometimes the easiest thing to do is to write a "shim" -- a (Simulink) MATLAB Function Block that has a few lines to establish size and types of variables, and then calls your MATLAB function to do the real work.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!