How to reference an m-file from a MATLAB Function block instead of embedding code in block?

1 view (last 30 days)
In Simulink, I'd like to make my MATLAB Function blocks more transparent to my version control system, git. If code inside the block changes, I want it to be very apparent in the git diff of an m-file. Without this, code changes in the block are hidden in the indecipherable diff of the containing Simulink model file.
Ideally, I could set up a MATLAB Function block to reference an m-file (*.m) instead of embedding the code in the block. Is this possible? How?

Answers (1)

Walter Roberson
Walter Roberson on 13 Nov 2020
If I recall correctly, it is not directly possible with .mlx files, but it was possible with .slx files by hacking the data structures (not something that methods were provided for.)
The work-around is to have the function block code be pretty much dummy code that mostly just calls the function by name. There is a possibility that you might need to put in the typing information, so it might not be quite as straight forward as
[out1, out2, out3] = MyFunction(in1, in2)
you might possibly need to initialize the datatypes and sizes of the outputs before making the call.

Categories

Find more on Programmatic Model Editing 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!