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

12 次查看(过去 30 天)
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 !!!

采纳的回答

Walter Roberson
Walter Roberson 2021-2-14
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by