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

14 ビュー (過去 30 日間)
Mark Golberg
Mark Golberg 2021 年 2 月 13 日
回答済み: Walter Roberson 2021 年 2 月 14 日
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 Center および File ExchangeSimulink Environment Customization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by