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

4 Ansichten (letzte 30 Tage)
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?

Antworten (1)

Walter Roberson
Walter Roberson am 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.

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by