How do I manage the contents of MATLAB Function blocks via source control?

5 visualizzazioni (ultimi 30 giorni)
I have a Simulink Model with MATLAB Function blocks. I want to manage the scripts inside these blocks with version control. Since the contents of the MATLAB Function blocks are embedded in the SLX file as binaries, I cannot identify readable changes to the MATLAB scripts using git. Is there a workaround for this?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 3 Mar 2021
Modificato: MathWorks Support Team il 3 Mar 2021
The most straightforward way to do this is via a nested function call, such that your MATLAB Function block contains a call to another MATLAB Function on your path which resides in a standalone M file. This way, you can manage the standalone M file with your source control software of choice. See an example below: 
% In the MATLAB Function Block code 
function y = fcn(u) 
y = foo(u); 
end 
% In a separate M file on the MATLAB Path: 
function z = foo(x) 
z = x^2; 
end 
This way, when the MATLAB Function Block is executed, it will call a function definition stored in a separate M file which can be managed line-by-line with source control. 
As another potential workaround, the Model Comparison Tool within Simulink is able to compare, merge, and revert changes to MATLAB Function blocks within SLX files. This tool can be integrated with git so that it is automatically launched when performing diff and merge commands.  
Here is a brief video which describes the Model Comparison Tool workflow and demonstrates it for a three-way merge: 
For more information about using the Comparison Tool for a two-way model merge, see the link below: 
For more information about configuring git to use the Model Comparison Tool, see the link below: 

Più risposte (0)

Categorie

Scopri di più su Interactive Model Editing in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by