How to link my custom MATLAB function into my Simulink model?

14 views (last 30 days)
Hello,
I have my custom matab function:
function [statusMessage , Files_TF] = doAllFilesExist_v2(dataPath , handles)
I'd like to add it to my simulink model, via some reference/link block or something like that.
I thought I could use MATLAB function block, but it's only for creating NEW functions. I do NOT want to re-create my function AGAIN.
Is there some way for me to create a "MATLAB (custom-existing-not-new) block" ?
THANKS !!!

Accepted Answer

Walter Roberson
Walter Roberson on 14 Feb 2021
No, there is not.
If it were a Level 2 S function (which we can see from the header it is not), then you would use https://www.mathworks.com/help/simulink/slref/level2matlabsfunction.html
If it were a Level 1 S function (which we can see from the header it is not), then you would use https://www.mathworks.com/help/simulink/slref/sfunction.html
However, what you have is a MATLAB Function, which needs to be incorporated through a MATLAB Function Block. In Simulink, MATLAB functions do not just float around as pure calls to MATLAB functions: they have to exist as blocks that have properties such as location and ports and signal attributes. And, unfortunately, MATLAB Function Blocks do not permit the source to be incoporated by reading it in from a file.
So... what you end up needing to do is create a MATLAB Function Block that doesn't do much except call your function.

More Answers (0)

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!