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

조회 수: 4 (최근 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 CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by